If you know that you are working from on a merge commit, you can list the files modified by the "merged branch" using :
git diff --name-only HEAD^...HEAD^2 # three dots
You may replace --name-only
with --name-status
if you want to also have an annotation saying if a file was added, modified or deleted.
If you need to know if a commit is a merge commit or a "regular" commit, you can check the answers to this question.
For example, adapting @MarekR's answer :
head_is_merge () {
# the return code of `git rev-parse HEAD^2` will say if it is a merge commit
git rev-parse HEAD^2 > /dev/null 2> /dev/null
}
if head_is_merge; then
# HEAD is a merge commit
else
# HEAD is a regular commit
fi
Some explanations :
HEAD^
(resp. HEAD^2
) points to the first parent (resp. the second parent) of the active commit.
obviously : HEAD^2
exists only if the active commit is a merge commit ; if it isn't, git will error
git diff A...B
is a shortcut, to indicate "the diff from the point where A
and B
forked, and B
itself"
from git help diff
:
git diff [<options>] <commit>...<commit> [--] [<path>…]
This form is to view the changes on the branch containing and up to the second <commit>
, starting at a common ancestor of both <commit>
. git diff A...B
is equivalent to git diff $(git merge-base A B) B
.