Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show parents of uncommitted merge in git

Tags:

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.

like image 289
Stephen Rasku Avatar asked Nov 12 '22 16:11

Stephen Rasku


1 Answers

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:

#!/bin/sh
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
    done
fi
like image 59
Edward Thomson Avatar answered Nov 15 '22 04:11

Edward Thomson