简体   繁体   English

相当于git checkout我们/他们的子模块

[英]Equivalent of git checkout ours/theirs for submodules

When resolving a conflict in a file I can 在解决文件中的冲突时我可以

git checkout --ours filename

and then commit the file. 然后提交该文件。 This will resolve the conflict. 这将解决冲突。 However, 然而,

git checkout --ours submodule

doesn't seem to work. 似乎不起作用。 The reference commit for the submodule doesn't change. 子模块的引用提交不会更改。

What would be the equivalent of git checkout --ours filename when resolving conflicts in submodule references? 什么是相当于git checkout --ours filename在解决子模块引用中的冲突时的git checkout --ours filename

Considering your next question , you can try a checkout of one of the three stages for your submodule: 考虑下一个问题 ,您可以尝试检查子模块的三个阶段之一:

git checkout -1 -- submodule # common ancestor
git checkout -2 -- submodule # source
git checkout -3 -- submodule # destination or MERGE_HEAD

Once a gitlink of a submodule has been changed, don't forget a git submodule update , to refresh its content. 一旦子模块的gitlink被更改,不要忘记git submodule update ,以刷新其内容。

The OP Amiramix refers to this quora answer , where Berk D. Demir , Production Engineer at Facebook, adds: OP Amiramix指的是这个quora答案 ,Facebook的生产工程师Berk D. Demir补充道:

git checkout -1 file

...will checkout the file from the ancestor of two branches. ...将从两个分支的祖先签出文件。
This is neither "ours" nor "theirs". 这既不是“我们的”也不是“他们的”。 It's the version of the file right before these two branches diverged. 这是两个分支分歧之前的文件版本。 Quite handy. 非常方便。

As you can guess, parameter -2 is for the version from HEAD and -3 is version from MERGE_HEAD accordingly. 你可以猜到,参数-2是针对HEAD的版本而-3是来自MERGE_HEAD版本。

Another way to reach these files through all other git commands is to use the symbolic-refs of commits. 通过所有其他git命令访问这些文件的另一种方法是使用提交的symbolic-refs。
git checkout MERGE_HEAD -- file gives the same effect with --theirs or -3 . git checkout MERGE_HEAD -- file--theirs-3给出相同的效果。

Another handy syntax when dealing with merge conflicts is the colon-stage-colon prefix to path. 处理合并冲突时另一个方便的语法是路径的冒号阶段冒号前缀。 git show :3:file will show the file (not the diff) from MERGE_HEAD . git show :3:file将显示来自MERGE_HEAD的文件(不是diff)。

A tiny cheat sheet: 一个很小的备忘单:

-1 == $(git merge-base HEAD MERGE_HEAD)
-2 == --ours == HEAD
-3 == --theirs == MERGE_HEAD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM