When I do git diff COMMIT I see the changes between that commit and HEAD (afaik) but I would like to see the changes that were made by that single commit.

I haven't found any obvious options on diff/log that will give me that output.

share|improve this question
2  
possible duplicate of Shorthand for diff of git commit with its parent? – Chris Maes Mar 10 '15 at 15:54

12 Answers 12

up vote 760 down vote accepted

To see the diff for a particular COMMIT hash:

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.

Alternatively, git show COMMIT will do something very similar. (The commit's data, including its diff.) See the git show manpage.

share|improve this answer
9  
Note that the ^ needs to be quoted in the Thomson and Bourne shells (synonym for | there) and rc and its derivatives (caret operator) and in zsh with extendedglob enabled (not globbing operator) – Stephane Chazelas Mar 24 '14 at 14:34
1  
This doesnt work anymore. git diff HEAD^ HEAD doesn't show anything. – user3690202 Jun 7 '15 at 17:16
8  
git diff COMMIT~ COMMIT works for me, notice the tilde instead of caret. I'm running git version 2.6.1.windows.1 on Windows 10. – Juuso Ohtonen Nov 24 '15 at 10:58
5  
@tradetree: the word COMMIT is supposed to be replaced with the name of some commit, e.g. the SHA sum. – Kundor May 12 '16 at 19:00
11  
I feel like git show is more appropriate for this question and should be the suggestion mentioned first. – pypmannetjies Oct 12 '16 at 12:00

As mentioned in "Shorthand for diff of git commit with its parent?", you can also use git diff with:

git diff COMMIT^!

or

git diff-tree -p COMMIT

With git show, you would need (in order to focus on diff alone) to do:

git show --color --pretty=format:%b $COMMIT

The COMMIT parameter is a commit-ish:

A commit object or an object that can be recursively dereferenced to a commit object. The following are all commit-ishes: a commit object, a tag object that points to a commit object, a tag object that points to a tag object that points to a commit object, etc.

See gitrevision "SPECIFYING REVISIONS" to reference a commit-ish.
See also "What does tree-ish mean in Git?".

share|improve this answer
16  
Thanks for mentioning the handy shortcut using bang! That's exactly what I came to this thread looking for. – patrickvacek Feb 3 '14 at 15:54
1  
git diff-tree -p COMMIT worked for me. Others didn't work. Thanks – Radian Nov 5 '14 at 9:12
    
instead of COMMIT I can type SHA? Anything else? – Honey Sep 1 '16 at 9:44
1  
@hon yes, it is called a tree-ish. I am on my phone, I will edit this answer in a bit. – VonC Sep 1 '16 at 9:51
1  
@Honey Actually, the exact term is commit-ish. I have edited my answer, with link to the official documentation defining this specific category. – VonC Sep 1 '16 at 11:01

You can also try this in easy way :

git show <COMMIT>
share|improve this answer
    
That's already been said in the accepted answer. – GKFX Jul 15 '16 at 14:11
1  
@GKFX : Dear sometimes person don't want to read 2 to 3 line. – Lakhan Jul 15 '16 at 19:05
4  
This should be the accepted answer IMHO. Simple and exactly what I was looking for. – mercurial Jan 3 at 14:46

git show shows the changes made in the most recent commit.

Equivalent to git show HEAD.

git show HEAD~1 takes you back 1 commit.

share|improve this answer

From the man page for git-diff(1):

git diff [options] [<commit>] [--] [<path>…]
git diff [options] --cached [<commit>] [--] [<path>…]
git diff [options] <commit> <commit> [--] [<path>…]
git diff [options] <blob> <blob>
git diff [options] [--no-index] [--] <path> <path>

Use the 3rd one in the middle:

git diff [options] <parent-commit> <commit>

Also from the same man page, at the bottom, in the Examples section:

$ git diff HEAD^ HEAD      <3>

Compare the version before the last commit and the last commit.

Admittedly it's worded a little confusingly, it would be less confusing as

Compare the most recent commit with the commit before it.

share|improve this answer
3  
Your rewording would apply to git diff HEAD HEAD^. – Richard Jun 26 '14 at 15:56
    
git diff HEAD^ HEAD doesn't display any changes. – user3690202 Jun 7 '15 at 17:16
    
@user3690202 so that implies that there aren't any changes to display. Is that actually the case? – user456814 Jun 8 '15 at 2:39
    
How can there not be any changes to display? If you want to view the last commit, surely unless it is a completely new repository there will be some changes to display? – user3690202 Jun 9 '15 at 19:06
    
@user3690202 it's possible to make an "empty commit" with Git that doesn't actually contain any changes from the parent, although there is a built-in safeguard that checks for and prevents this, though it is overridable with a command line option. I doubt that you would intentionally create an empty commit, so another possibility is that you somehow have pre-commit line-ending conversion on (or other funny whitespace stuff) that is tricking Git into thinking that no changes have actually been made. What platform are you running Git on? – user456814 Jun 10 '15 at 0:21

this seems to do the job; i use it to show what has been brought in by a merge.

    git whatchanged -m -n 1 -p <sha of merge commit>
share|improve this answer
    
Would that work too with git log? (because of stackoverflow.com/a/18585297/6309) – VonC Oct 14 '14 at 17:52

Another possibility:

git log -p COMMIT -1

share|improve this answer
    
also git show COMMIT gives the same output – Grant McLean Feb 24 '16 at 9:16
1  
@GrantMcLean Yes, and it is already in the highest upvoted answer, so I do not mention it. – John_West Feb 24 '16 at 13:40
git difftool COMMIT^ <commit hash>

is also possible if you have configured your difftool.

See here how to configure difftool Or the manual page here

Additionally you can use git diff-tree --no-commit-id --name-only -r <commit hash> to see which files been changed/committed in a give commit hash

share|improve this answer

To see author and time by commit use git show COMMIT. Which will result in something like this:

commit 13414df70354678b1b9304ebe4b6d204810f867e
Merge: a2a2894 3a1ba8f
Author: You <you@you.com>
Date:   Fri Jul 24 17:46:42 2015 -0700

     Merge remote-tracking branch 'origin/your-feature'

If you want to see which files had been changed, run the following with the values from the Merge line above git diff --stat a2a2894 3a1ba8f.

If you want to see the actual diff, run git --stat a2a2894 3a1ba8f

share|improve this answer

you could use git diff HEAD HEAD^1 to see the diff with the parent commit.

if you only wanna see the list of files, add the option --stat into it.

share|improve this answer

this command will get you the git parent commit-hash

git log -n 2 <commit-hash>

after that git diff-tool <commit-hash> <parent-commit-hash>

Ex:

bonnie@bonnie ~/ $ git log -n 2 7f65b9a9d3820525766fcba285b3c678e889fe3

commit 7f65b9a9d3820525766fcba285b3c678e889fe3b
Author: souparno <souparno.majumder@gmail.com> 
Date:   Mon Jul 25 13:17:07 2016 +0530

css changed to maintain the aspect ratio of the channel logos and to fit them properly

commit c3a61f17e14e2b80cf64b172a45f1b4826ee291f
Author: souparno <souparno.majumder@gmail.com>
Date:   Mon Jul 25 11:28:09 2016 +0530

the ratio of the height to width of the channel images are maintained

after this

git difftool 7f65b9a9d3820525766fcba285b3c678e889fe3b c3a61f17e14e2b80cf64b172a45f1b4826ee291f
share|improve this answer

I'm running git version 2.6.1.windows.1 on Windows 10, so I needed a slight modification to Nevik's answer (tilde instead of caret):

git diff COMMIT~ COMMIT

Other option is to quote the caret:

git diff "COMMIT^" COMMIT
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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