How to show diff for a rev?

John Meinel john at arbash-meinel.com
Wed Jun 18 05:37:07 UTC 2014


Git has the ability to show you what changed in a commit using "git show
COMMIT" and something like "git diff COMMIT^!".
However, they don't work quite like what I expected, and I'm wondering if
anyone has hints that could help.

Specifically, I want to look at "what are the changes brought in by this
commit". Equivalent to what in Bazaar would be:
  bzr diff -c 4567

It seems like "git show deadbeat" and "git diff deadbeef^!" work like I
want when there is a single parent (just a simple commit). The issue for me
is that I want to see a similar diff for a merge commit.
I realize that in git it models merge commits slightly differently. Again
it doesn't have a preference for a mainline, so by default diff of a merge
commit is just the differences in the merge that *aren't* in the parents. I
can understand that PoV, but I'd like to find a way to express the other
PoV as well.

The main problem with merge commits is that "git diff deadbeef^!" shows me
the *reverse* diff.

For a concrete example, take the recent merge:
7360086 Better status information when a relation hook fails

git diff 7360086^ 7360086
Shows me what I want. (or git diff 7360086^1 7360086)

git log -p 7360086
  shows no diff for that revision
git show 7360086
  similarly, no diff.
git diff 7360086^2 7360086
  Is the diff against the merged in parent, which is appropriately nothing.

git diff 7360086^!
  is the reverse of the diff I want

Maybe:
git diff 7360086^@
This seems to give me the diff I was looking for, but that might be
accidentally. "man git-rev-parse" says this is:
A suffix ^ followed by an at sign is the same as listing all parents of
<rev> (meaning, include anything reachable from its parents, but not the
commit itself).

So it sounds like that is actually doing:
git diff 7360086^1 7360086^2
(Show me the diff of the one parent vs the other parent).
It happens to be correct this time because we have a simple no-change merge.


Now I'm even more confused, because I went to a different revision, which
is a simple merge that isn't a trivial (could have been fast forwarded)
348c104 Ensure availability command output.

If I do:
  git show 348c104
It has no diff, as I would have expected.
If I do:
  git diff 348c104^ 348c104
It looks like I would expect. And this
  git diff 348c104^!
Also works.
However as I was worried about:
 git diff 348c104^@
Is showing me the changes introduced by one parent, and the *removal* of
all the changes that were in mainline at that point.

So the only syntax that reliably gives me what I want is:
 git dif 348c104^ 348c104
I was hoping there would be a better shortcut for it. Does anyone have some
more voodoo that I could use to avoid having to type the same thing twice?

(I guess since git commit ids are 7 digit hexadecimal I almost never type
them and almost always copy&paste, so it isn't *that* much harder to type
it twice. I do miss "bzr diff -c 5678", though.)

John
=:->
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju-dev/attachments/20140618/e25952a2/attachment.html>


More information about the Juju-dev mailing list