简体   繁体   中英

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?

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.

The OP Amiramix refers to this quora answer , where Berk D. Demir , Production Engineer at Facebook, adds:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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