OP: What does the caret (^) character mean in Git?
The ^ (Caret) and ~ (Tilde) selectors
The difference between HEAD^
(Caret) and HEAD~
(Tilde) is how they traverse history backwards from a specified starting point, in this particular case HEAD
.
Tilde ~
<rev>~[<n>]
= select <n>th
generation ancestor, following only first* parents
Caret ^
<rev>^[<n>]
= select <n>th
parent of first generation ancestors
*First parent is always the left hand side of the merge, e.g. the commit on the branch that got merged into.
Joining ~ and ^ together
As seen in the illustration below the two selectors ~ and ^ can be used in combination. Also note that instead of using HEAD
as a starting point, any regular reference can be used such as a branch, tag or even a commit hash.
Further more, depending on what ancestor is intended to be selected ^ and ~ can be used interchangeably as seen below in the table.
Source: A thorough rundown can be found in this blog post on the subject.
^
) is the escape character in cmd.exe. Every time I've tried to use it to see if it would be helpful I was actually passing nothing, which explains why the results were never different. >_> Stupid cmd.exe. You can escape it by doubling it or quoting it:git log master^^
orgit log "master^"
– Lorrianelorrie