How to diff a commit with its parent
Use:
git diff 15dc8^!
as described in the following fragment of git-rev-parse(1) man page (or in modern Git gitrevisions(7) man page):
Two other shorthands for naming a set that is formed by a commit and itsparent commits exist. The r1^@ notation means all parents of r1. r1^!includes commit r1 but excludes all of its parents.
This means that you can use 15dc8^!
as a shorthand for 15dc8^..15dc8
anywhere in Git where revisions are needed. For the diff command, the git diff 15dc8^..15dc8
is understood as git diff 15dc8^ 15dc8
, which means the difference between parent of commit (15dc8^
) and commit (15dc8
).
Note: the description in git-rev-parse(1)
man page talks about revision ranges, where it needs to work also for merge commits, with more than one parent. Then r1^!
is "r1 --not r1^@
" i.e. "r1 ^r1^1 ^r1^2 ...
"
Also, you can use git show COMMIT
to get the commit description and diff for a commit. If you want only the diff, you can use git diff-tree -p COMMIT
.
If you know how far back, you can try something like:
# Current branch vs. parentgit diff HEAD^ HEAD# Current branch, diff between commits 2 and 3 times backgit diff HEAD~3 HEAD~2
Prior commits work something like this:
# Parent of HEADgit show HEAD^1# Grandparentgit show HEAD^2
There are a lot of ways you can specify commits:
# Great grandparentgit show HEAD~3