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.
HEAD~1 refers to the commit's first parent. HEAD~2 refers to the first parent of the commit's first parent. ^<n> refers to the the <n>th parent. HEAD^1 refers to the commit's first parent. HEAD^2 refers to the commit's second parent.
When working with Git, only one branch can be checked out at a time - and this is what's called the "HEAD" branch. Often, this is also referred to as the "active" or "current" branch. Git makes note of this current branch in a file located inside the Git repository, in . git/HEAD .
The difference between HEAD^ (Caret) and HEAD~ (Tilde) is how they traverse history backwards from a specified starting point, in this particular case HEAD .
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. See related answer to What’s the difference between HEAD^ and HEAD~ in Git?
For the full details, see the “Specifying Revisions” section of git rev-parse --help.
It means "parent of". So HEAD^ means "the parent of the current HEAD". You can even chain them together: HEAD^^ means "the parent of the parent of the current HEAD" (i.e., the grandparent of the current HEAD), HEAD^^^ means "the parent of the parent of the parent of the current HEAD", and so forth.
The ^ (caret) can also be used when specifying ranges.
To exclude commits reachable from a commit, a prefix ^ notation is used. E.g. ^r1 r2 means commits reachable from r2 but exclude the ones reachable from r1.
<rev>
Include commits that are reachable from (i.e. ancestors of) .
^<rev>
Exclude commits that are reachable from (i.e. ancestors of) .
Here's a visual explanation. Suppose you have a history like so:
master
... <- B <- C <- D
/
... <- E <- F
feature
When feature was merged into master, C was created with two ancestors. Git assigns these ancestors numbers. The mainline ancestor B is assigned 1 and the feature ancestor F is assigned 2.
Thus C^1 refers to B and C^2 refers to F. C^ is an alias for C^1.
You would only ever use <rev>^3. if you had performed a merge of three branches.
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 carat represents a commit offset (parent). So for instance, HEAD^ means "one commit from HEAD" and HEAD^^^ means "three commits from HEAD".
The (^) gets the parent source of the command i.e. HEAD^ will get the parent of HEAD.
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