How to "git show" a merge commit with combined diff output even when every changed file agrees with one of the parents?

Tilman Vogel picture Tilman Vogel · Feb 22, 2011 · Viewed 108.9k times · Source

After doing a "simple" merge (one without conflicts), git show usually only shows something like

commit 0e1329e551a5700614a2a34d8101e92fd9f2cad6 (HEAD, master)
Merge: fc17405 ee2de56
Author: Tilman Vogel <email@email>
Date:   Tue Feb 22 00:27:17 2011 +0100

Merge branch 'testing' into master

This is because, for merges, git show uses the combined diff format which omits files that agree with either of the parent versions.

Is there a way to force git to still show all differences in combined diff mode?

Doing git show -m will show the differences (using pairwise diffs between the new and all parent versions respectively) but I would prefer to have that with the differnces marked by +/- in the respective columns like in combined mode.

Answer

rip747 picture rip747 · Sep 7, 2011

Look at the commit message:

commit 0e1329e551a5700614a2a34d8101e92fd9f2cad6 (HEAD, master)
Merge: fc17405 ee2de56
Author: Tilman Vogel <email@email>
Date:   Tue Feb 22 00:27:17 2011 +0100

Merge branch 'testing' into master

notice the line:

Merge: fc17405 ee2de56

take those two commit ids and reverse them. so in order get the diff that you want, you would do:

git diff ee2de56..fc17405

to show just the names of the changed files:

git diff --name-only ee2de56..fc17405

and to extract them, you can add this to your gitconfig:

exportfiles = !sh -c 'git diff $0 --name-only | "while read files; do mkdir -p \"$1/$(dirname $files)\"; cp -vf $files $1/$(dirname $files); done"'

then use it by doing:

git exportfiles ee2de56..fc17405 /c/temp/myproject