When I specify an ancestor commit object in Git, I'm confused between HEAD^ and HEAD~.
Both have a "numbered" version like HEAD^3 and HEAD~2.
They seem very similar or the same to me, but are there any difference?
When I specify an ancestor commit object in Git, I'm confused between HEAD^ and HEAD~.
Both have a "numbered" version like HEAD^3 and HEAD~2.
They seem very similar or the same to me, but are there any difference?
HEAD^^^ is the same as HEAD~3, selecting the third commit before HEAD
HEAD^2 specifies the second head in a merge commit
The ^<n> format allows you to select the nth parent of the commit (relevant in merges). The ~<n> format allows you to select the nth ancestor commit, always following the first parent. See git-rev-parse's documentation for some examples.
HEAD~ specifies the first parent on a "branch"
HEAD^ allows u to select a specific parent of the commit
An Example:
If you want to follow a side branch, you have to specify something like
master~209^2~15
HEAD^ means the first parent of the tip of the current branch.
Remember that git commits can have more than one parent. HEAD^ is short for HEAD^1, and you can also address HEAD^2 and so on as appropriate.
You can get to parents of any commit, not just HEAD. You can also move back through generations: for example, master~2 means the grandparent of the tip of the master branch, favoring the first parent in cases of ambiguity. These specifiers can be chained arbitrarily
, e.g., topic~3^2.
For the full details, see "Specifying Revisions" in the git rev-parse documentation.