Reputation: 509
I was trying to get the diff for a commit with the message Add structure
shown below, but git diff fb237ff
shows the diff for the commit "Add title"
instead. How can I get the diff for the SHA
I want instead of the child of this commit?:
commit 31013a1 (HEAD -> master, origin/master)
Author: user.name <user.email>
Date: Sun Jun 17 19:28:52 2018 +0100
Add title
commit fb237ff
Author: user.name <user.email>
Date: Sun Jun 17 19:24:33 2018 +0100
Add structure
commit 69d64b4
Author: user.name <user.email>
Date: Sun Jun 17 19:10:26 2018 +0100
Add heading
Upvotes: 1
Views: 1135
Reputation: 372
git diff <commit>
shows you the difference between your working directory and <commit>. So in your case, that would indeed be the contents of 31013a1 (plus whatever other uncommited changes you may have).
In order to see the changes that one commit introduced, you can do:
git show <commit>
Upvotes: 1
Reputation: 72216
git diff
accepts one or two revisions to compare. When only one is provided then it compares the working tree against it.
If you posted the output of git log -n 3
then HEAD
is 31013a1
and the following Git commands are equivalent:
git diff fb237ff
git diff HEAD~1
If you want to show the changes introduced by the commit fb237ff
then you have to compare it with its parent (69d64b4
). You can use any of the following commands for this purpose:
git diff 69d64b4 fb237ff
git diff fb237ff~1 fb237ff
git diff HEAD~2 HEAD~1
Read the documentation of git diff
and how to specify Git revisions.
Upvotes: 1
Reputation: 11060
git diff SHA
shows the differences from the named commit to the current HEAD - which will be everything that has changed since that commit was made - i.e the latest commit.
You probably want git show SHA
to show you the changes contained in that commit, or git log -p
to show the commit message and changes.
Upvotes: 4