Git - easiest way to see diff with previous version if I have the sha

26,351

Solution 1

git show is your friend:

git show shaOfHisCheckIn

Solution 2

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^!

Solution 3

Try this:

git diff shaOfHisCheckIn^ shaOfHisCheckIn

or

git diff shaOfHisCheckIn{^,}

Solution 4

git diff shaOfHisCheckIn shaOfHisCheckIn^

Share:
26,351
andriy
Author by

andriy

A .NET developer in the Germany/France/Switzerland border area. I do web development, desktop development, Selenium automation, and lots more. Currently employed at Dreamlines GmbH. I can help you transition your team to Git automate your regression tests release your next great ASP.NET MVC, WPF, or even WinForms app chase down those hard-to-catch bugs write tests for things that are hard to test I speak fluent English, excellent Romanian, and pretty good German. And a smattering of French, at least enough to tell the airport taxi drivers how to find my house.

Updated on July 24, 2020

Comments

  • andriy
    andriy almost 4 years

    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?

  • andriy
    andriy almost 13 years
    Thanks, that's exactly what I need, and it's easy to remember and to type.
  • Simon Whitaker
    Simon Whitaker almost 13 years
    You're welcome! It works for tags too by the way (git show <tag>) - it's a really useful command.
  • Peter Mortensen
    Peter Mortensen almost 6 years
    Isn't Vinoth Gopi's answer more appropriate (the order)?