Reputation: 8277
what is the difference between git diff HEAD^ HEAD
or git diff HEAD~ HEAD
and this git diff HEAD^1
or git diff HEAD~1
?
I understand the ones git diff HEAD^ HEAD
= git diff HEAD~ HEAD
.
and so is git diff HEAD^1
= git diff HEAD~1
..
are all these diff yielding same output in any case?
Upvotes: 1
Views: 129
Reputation: 1512
I think the main confusion isn't about git diff
but about HEAD
and HEAD^[num]
and HEAD~[num]
.
EDIT:
HEAD
means the current branch you are working at.
And HEAD^[num]
means the num'th parent point of a multi-parent node. For a single parent node, [Commit]^[2 or greater] is an invalid expression. ( And git will warn this by fatal: ambiguous argument '1f9a20d^2': unknown revision or path not in the working tree.
)
The HEAD~[num]
means the num'th ancester commit of a commit node. For a merging node, the ancester is the branch branch you were on when you merged.
Ref this link and this link to read more about HEAD
related.
The following picture shows a several way of using Ancestry References in a quite simple situation.
ps. Sincecely apology for previous wrong answer and thanks @torek a lot for correcting it out.
Upvotes: 5
Reputation: 391
Your examples are not equivalent. If you do not specify a commit to compare against then the diff will contain working tree changes, staged or not.
So, git diff HEAD^
will include working tree changes in the commit, while git diff HEAD^ HEAD
will not include working tree changes and will only include the diff between the two commits.
HEAD^
, HEAD~
, HEAD^1
, and HEAD~1
are all identical. They all refer to the first parent of the HEAD
commit.
HEAD^^
, HEAD~~
, and HEAD~2
are identical, they all refer to the first parent of the first parent of the HEAD
commit. HEAD^2
is special - it refers the the second parent of the HEAD
commit, which is only useful if HEAD
is a merge commit.
More information here:
http://git-scm.com/book/ch6-1.html#Ancestry-References
Upvotes: 4