I know I can do:
git diff HEAD^..HEAD
But is there some shorthand that's easier to remember, like:
git diff foo N
where N
can be any number of commits from now to get a cumulative diff of?
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 .
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. Order does matter when you're comparing branches.
To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.
"git diff" always show the difference between two commits (or commit and working directory, etc.).
From the SPECIFYING REVISIONS of the git rev-parse
man page:
A suffix
~<n>
to a revision parameter means the commit object that is the<n>
th generation grand-parent of the named commit object, following only the first parent.
I.e.rev~3
is equivalent torev^^^
which is equivalent torev^1^1^1
.
Consider the examples in the git diff
man page:
git diff HEAD^..HEAD git diff HEAD^.. git diff HEAD^ HEAD
are equivalent forms (thanks chrisk for the HEAD^..
form, as mentioned in the comments).
(they are not equivalent to git diff HEAD^
, as Mark Longair comments, since it diff
with the working directory, not the last commit)
So:
git diff HEAD~15 # diff the working tree with the 15th previous commit git diff HEAD~15 HEAD # diff the last commit with the 15th previous commit
should do what you need (as khmarbaise mentions in the comment).
Use git diff HEAD~N
. Or use git diff HEAD~N..
to exclude uncommitted changes.
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