等价于 git checkout ours/theirs 子模块
Equivalent of git checkout ours/theirs for submodules
解决文件中的冲突时,我可以
git checkout --ours filename
然后提交文件。这将解决冲突。然而,
git checkout --ours submodule
好像不行。子模块的参考提交没有改变。
在解决子模块引用中的冲突时,git checkout --ours filename
的等价物是什么?
,您可以尝试检查子模块的三个阶段之一:
git checkout -1 -- submodule # common ancestor
git checkout -2 -- submodule # source
git checkout -3 -- submodule # destination or MERGE_HEAD
一旦更改了子模块的 gitlink,请不要忘记 git submodule update
,以刷新其内容。
Facebook 生产工程师 OP Amiramix refers to this quora answer, where 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.
Another way to reach these files through all other git commands is to use the symbolic-refs of commits.
git checkout MERGE_HEAD -- file
gives the same effect with --theirs
or -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
.
A tiny cheat sheet:
-1 == $(git merge-base HEAD MERGE_HEAD)
-2 == --ours == HEAD
-3 == --theirs == MERGE_HEAD
解决文件中的冲突时,我可以
git checkout --ours filename
然后提交文件。这将解决冲突。然而,
git checkout --ours submodule
好像不行。子模块的参考提交没有改变。
在解决子模块引用中的冲突时,git checkout --ours filename
的等价物是什么?
git checkout -1 -- submodule # common ancestor
git checkout -2 -- submodule # source
git checkout -3 -- submodule # destination or MERGE_HEAD
一旦更改了子模块的 gitlink,请不要忘记 git submodule update
,以刷新其内容。
Facebook 生产工程师 OP Amiramix refers to this quora answer, where 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 fromMERGE_HEAD
accordingly.Another way to reach these files through all other git commands is to use the symbolic-refs of commits.
git checkout MERGE_HEAD -- file
gives the same effect with--theirs
or-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) fromMERGE_HEAD
.A tiny cheat sheet:
-1 == $(git merge-base HEAD MERGE_HEAD)
-2 == --ours == HEAD
-3 == --theirs == MERGE_HEAD