39

A colleague of mine checked in some changes to Git, and I want to see exactly what those changes were. In other words, the diff between his check-in and its parent.

What seemed logical to me was to run this command:

git diff shaOfHisCheckIn

But this didn't work. It appears to show the diff between that SHA and my current working copy.

What's the correct command to show the diff between a given SHA and its parent?

Ryan Lundy
  • 204,559
  • 37
  • 180
  • 211

4 Answers4

66

git show is your friend:

git show shaOfHisCheckIn
Simon Whitaker
  • 20,506
  • 4
  • 62
  • 79
6

If you want to view the diff visually in kdiff3, meld, kompare, xxdiff, tkdiff, diffuse

git difftool --dir-diff shaOfHisCheckIn^!

git difftool --tool=meld --dir-diff shaOfHisCheckIn^!

git difftool -t meld -d shaOfHisCheckIn^!
Denilson Sá Maia
  • 47,466
  • 33
  • 109
  • 111
5

Try this:

git diff shaOfHisCheckIn^ shaOfHisCheckIn

or

git diff shaOfHisCheckIn{^,}
Vinoth Gopi
  • 734
  • 4
  • 11
2

git diff shaOfHisCheckIn shaOfHisCheckIn^

Jonas Heidelberg
  • 4,984
  • 1
  • 27
  • 41
  • Isn't [Vinoth Gopi's answer](https://stackoverflow.com/questions/6128131/git-easiest-way-to-see-diff-with-previous-version-if-i-have-the-sha-1-hash/6128240#6128240) more appropriate (the order)? – Peter Mortensen Jul 21 '18 at 10:46