Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 522
Greg Avatar asked Dec 14 '16 19:12

Greg


1 Answers

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
like image 172
VonC Avatar answered Oct 10 '22 10:10

VonC