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?
You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.
The diff can be done with git diff (followed by the filename or nothing if you want to see the diff of all modified files). But if you already did something like git add * , you have to undo with git restore --staged .
To see the diff for a particular COMMIT hash, where COMMIT is the hash of the commit: git diff COMMIT~ COMMIT will show you the difference between that COMMIT 's ancestor and the COMMIT . See the man pages for git diff for details about the command and gitrevisions about the ~ notation and its friends.
Your file is already staged to be committed. You can show it's diff using the --cached option of git. To unstage it, just do what git status suggests in it's output ;) You can check The Git Index For more info.
git show
is your friend:
git show shaOfHisCheckIn
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^!
Try this:
git diff shaOfHisCheckIn^ shaOfHisCheckIn
or
git diff shaOfHisCheckIn{^,}
git diff shaOfHisCheckIn shaOfHisCheckIn^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With