git submodule merge conflict: how to visualize?
I was pretty happy when I found out lately about
git submodule summary
which shows me nicely by which commits the checked out commit of a submodule is ahead or behind the reference in the reposit开发者_Go百科ory.
Now when I am in the middle of a merge with submodule conflicts, the same command does not produce useful output. I need a painful sequence of gitk in my main tree examining the branches, along with cd'ing into the submodules, fetching and gitk in there, comparing sha1 values...
What would be a more convenient way to get the picture of the conflict?
You can make a script. Here is the core of such a script:
git --git-dir=submodulepath/.git diff \
$(git ls-tree HEAD submodulepath | cut -c 15-54) \
$(git ls-tree MERGE_HEAD submodulepath | cut -c 15-54)
you can replace diff with log or any number of other commands that will help you see what the changes are. One would be to see if it would be a fast-forward merge in which case you can resolve the conflict quickly without merging at the submodule level.
There is also gitslave which will help you with such issues.
Hope this helps.
Same as Adam's answer, but using the index and without cut:
sub="path/to/submodule"
git --git-dir="$sub/.git" diff \
$(git rev-parse ":2:$sub") \
$(git rev-parse ":3:$sub")
Explanation:
When there is a conflict, Git stores information about it in the index. It stores several different versions, so-called stages. Stage 1 is the "base" version (common ancestor), stage 2 is the "ours" version and stage 3 is the "theirs" version.
In case of file conflicts, the index contains the blob object IDs for the different versions. In case of submodules, it's the submodule commit IDs. In the command above, :2:$sub
refers to stage 2
(ours) of the submodule at path $sub
.
Note that you can see a list of index entries with stages using git ls-files --stage
.
精彩评论