Stephen Rasku Stephen Rasku - 4 months ago 23
Git Question

Show parents of uncommitted merge in git

How can I see the parents of an uncommitted merge in git? I can see one parent by doing

git log -1
but how do I see the other parent?

This is easy to do in Mercurial:

$ hg parents
changeset: 2:b65656dbfff6
tag: tip
parent: 0:1806d848df54
user: Stephen Rasku
date: Tue Nov 27 10:14:31 2012 -0800
summary: c

changeset: 1:9aaa22944f41
user: Stephen Rasku
date: Tue Nov 27 10:14:01 2012 -0800
summary: b

Is there anything equivalent in git? I know you can see the parents of a committed merge in git. This is specifically to see the parents of an uncommitted merge.


The sources of an uncommitted merge are stored in .git/MERGE_HEAD. If you are performing an octopus merge, you will have multiple commit IDs in this file, newline delimited. The target of the merge, of course, HEAD.

If you want a detailed output, similar to the example you provided from Mercurial, you can feed that into git log, as you noted. It may be easiest to write a shell script to handle this.

If you were to name this script git-parents, and place it in your path, you could simply run git parents to get a similar experience to what you described:

git --no-pager log -1

WORKDIR=`git rev-parse --show-toplevel`
if [ -f "${WORKDIR}/.git/MERGE_HEAD" ]; then
    for a in `cat "${WORKDIR}/.git/MERGE_HEAD" | xargs` ; do
        git --no-pager log -1 $a