I want to know the identity of the "common ancestor" commit during a git merge conflict resolution.
Said differently: I want to know the hash of the revision that the BASE version is being drawn from when I'm resolving conflicts during a git merge
.
Hopefully, there is a command that will tell me this information?
Why I want to know
- I am (unfortunately) doing a very complicated merge, with lots of conflicts.
- I want to be able to visualize the two change paths (
BASE -> LOCAL
andBASE -> REMOTE
) to give me more context about how these two sets of changes happened, who made them, when, on what branches, etc...
Helpful (?) related info
Recall that for any particular conflicting file, there is
- a BASE version (
git show :1:<path>
), which comes from the common ancestor commit (whose identity is the answer to my question) - the LOCAL (branch I was on:
git show :2:<path>
) version and - the REMOTE (branch I'm merging in:
git show :3:<path>
) version
- a BASE version (
I know that I can get the SHA hash of the BASE file itself, by using
git ls-files -u
, which gives output like
$ git ls-files -u | grep "<path>"
100644 <SHA of BASE file> 1 <path>
100644 <SHA of LOCAL file> 2 <path>
100644 <SHA of REMOTE file> 3 <path>
I am using
git mergetool
andgvimdiff3
to view conflicts. This tool shows each conflicting file (with the"<<<"
,">>>"
,"|||"
conflict markers, as well as three other files for reference: LOCAL, BASE, and REMOTE. All very well and good.My BASE files sometimes have conflict markers in them (!) which look like this:
<<<<<<<<< Temporary merge branch 1
<snip>
||||||||| merged common ancestors
=========
<snip>
>>>>>>>>> Temporary merge branch 2
- I am (I think) using the recursive merge strategy, which claims that:
When there is more than one common ancestor that can be used for 3-way merge, it creates a merged tree of the common ancestors and uses that as the reference tree for the 3-way merge.
- I guess what I am seeing is that the "common ancestor" is a merged hybrid of several commits. Nevertheless, that merged hybrid must have been generated somehow, must have a SHA, and must have parents whose identities I want to know.