HEAD is a pointer at the current branch. I have seen a variety of notations for ancestors of HEAD including
HEAD~2
HEAD^2
HEAD@{2}
HEAD~~
HEAD^^
What does each of the above mean, exactly? Where is the documentation for this?
git reference suffixes (^N, ~N, @{... }) ref~ is shorthand for ref~1 and means the commit's first parent. ref~2 means the commit's first parent's first parent. ref~3 means the commit's first parent's first parent's first parent.
The ~(tilde) and ^(caret) symbols are used to point to a position relative to a specific commit. The symbols are used together with a commit reference, typically HEAD or a commit hash.
The caret refers to the parent of a particular commit. E.g. HEAD^ refers to the parent of the current HEAD commmit. (also, HEAD^^ refers to the grandparent).
The difference between HEAD^ (Caret) and HEAD~ (Tilde) is how they traverse history backwards from a specified starting point, in this particular case HEAD .
From the docs here.
HEAD~2
: 2 commits older than HEADHEAD^2
: the second parent of HEAD, if HEAD was a merge, otherwise illegalHEAD@{2}
: refers to the 3rd listing in the overview of git reflog
HEAD~~
: 2 commits older than HEADHEAD^^
: 2 commits older than HEADIf HEAD was a merge, then
Some Combinations and Synonyms
First Parent First Grandparent Second Parent Second Grandparent HEAD~ HEAD^ HEAD~1 HEAD~2 HEAD^2 HEAD^2~ HEAD^1 HEAD^^ HEAD^2^
git reference suffixes (^N, ~N, @{...})
ref~
is shorthand for ref~1
and means the commit's first parent. ref~2
means the commit's first parent's first parent. ref~3
means the commit's first parent's first parent's first parent. And so on.
ref^
is shorthand for ref^1
and means the commit's first parent. But where the two differ is that ref^2
means the commit's second parent (remember, commits can have two parents when they are a merge).
The ^ and ~ operators can be combined.
Here's a diagram showing how to reference various commits using HEAD as the starting point.
src
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