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 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With