I saw an answer to a question here that helps restore a deleted file in git.
The solution was
git checkout ^ --
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) .
Greg Bacon gave a great link, but it's pretty dense. The Git introductory docs online also introduce revision and range specifiers:
https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection
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 carat represents a commit offset (parent). So for instance, HEAD^
means "one commit from HEAD" and HEAD^^^
means "three commits from HEAD".
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).