41

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?

4 Answers 4

68

git show is your friend:

git show shaOfHisCheckIn
2
  • Thanks, that's exactly what I need, and it's easy to remember and to type.
    – Ryan Lundy
    Commented May 25, 2011 at 17:17
  • 2
    You're welcome! It works for tags too by the way (git show <tag>) - it's a really useful command. Commented May 25, 2011 at 17:18
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^!
5

Try this:

git diff shaOfHisCheckIn^ shaOfHisCheckIn

or

git diff shaOfHisCheckIn{^,}
2

git diff shaOfHisCheckIn shaOfHisCheckIn^

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.