Subject: a diff equivalent to show?

From: Brian Ericson <[email-masked]>
Date: Tue, 05 Jun 2012 11:39:43 -0500

Is there a way I can get the same results (files & diff content) using 
"git diff" that I can get using "git show"?  I ask because I want show's 
basic results (changes it represents via, for example, --name-status), 
but need the options and output of diff.

I'm interested, in particular, in three merge cases involving merges to 
master from "other" (see example repo below):
* other changed file (10241ee as "First merge.")
* master changed file (178f994 as "Second merge.")
* Conflicting merge resolved by keeping my changes (bc1291a as "Third 
merge.")

In all three cases, "show" shows no changes (via git show bc1291a 
178f994 10241ee).  However, I can't consistently get diff to replicate 
the show's result, as shown via
function differ() {
   local RESULT=$( git --no-pager diff --name-status $1 )
   printf "%-29s -- %s\n" "$1" "${RESULT:-OK}"
}

for commit in bc1291a 178f994 10241ee
do
   #Shouldn't this work?
   differ $commit^!
   #Should be equivalent to previous
   differ "^$commit^@ $commit"
   #Yet another way of representing the same thing.
   differ "^$commit^1 ^$commit^2 $commit"
   #Hrm...  This is also equivalent?!
   differ "^$commit^1 $commit"
   #I probably should (better) understand why order matters...
   differ "$commit ^$commit^@"
   #Thrown in for good measure.
   differ "^$commit^2 $commit"
   echo
done

which produces:
10241ee^!                     -- M    file
^10241ee^@ 10241ee            -- M    file
^10241ee^1 ^10241ee^2 10241ee -- M    file
^10241ee^1 10241ee            -- M    file
10241ee ^10241ee^@            -- OK
^10241ee^2 10241ee            -- OK

178f994^!                     -- A    unrelated_file
^178f994^@ 178f994            -- A    unrelated_file
^178f994^1 ^178f994^2 178f994 -- A    unrelated_file
^178f994^1 178f994            -- A    unrelated_file
178f994 ^178f994^@            -- OK
^178f994^2 178f994            -- M    file

bc1291a^!                     -- OK
^bc1291a^@ bc1291a            -- OK
^bc1291a^1 ^bc1291a^2 bc1291a -- OK
^bc1291a^1 bc1291a            -- OK
bc1291a ^bc1291a^@            -- M    file
^bc1291a^2 bc1291a            -- M    file

Tangentially, it seems odd to me that $commit^! seems equivalent to 
^$commit^1 $commit.  What's also odd to me is that, removing 
--name-status, "git --no-pager diff 10241ee^!" shows a "-1" -- exactly 
the opposite of what I'd expect ("+1"):
diff --git a/file b/file
index d00491f..e69de29 100644
--- a/file
+++ b/file
@@ -1 +0,0 @@
-1

Example repo to demonstrate:
git init && touch file && git add file && git commit -m 'Empty file.'
git checkout -b other && echo 1 >> file && git commit -am 'other 
appended 1 to file.'
git checkout master && git merge --no-ff -m 'First merge.'
git checkout master && git merge --no-ff -m 'First merge.' other
echo 2 >> file && git commit -am 'master appended 2 to file'
git checkout other && touch unrelated_file && git add unrelated_file && 
git commit -m 'other added unrelated_file.'
git checkout master && git merge -m 'Second merge.' other
echo 3 >> file && git commit -am 'master appended 3 to file'
echo 4 >> file && git commit -am 'master appended 4 to file'
git checkout other && echo 3 >> file && git commit -am 'other appended 3 
to file'
git checkout master && git merge other ; git checkout HEAD file && git 
commit #Edit commit to make first line "Third merge."

Here is the resulting tree:
*   bc1291a Third merge.
|\
| * 11ce5db other appended 3 to file
* | 9c92ac7 master appended 4 to file
* | 4bd6eda master appended 3 to file
* |   178f994 Second merge.
|\ \
| |/
| * fb424bf other added unrelated_file.
* | d854a9e master appended 2 to file
* |   10241ee First merge.
|\ \
| |/
| * 0d73874 other appended 1 to file.
|/
* 468a04b Empty file.

I am using git version 1.7.10.2.