What does `git checkout ...` do?

Git

Git Problem Overview


I occasionally accidentally write git checkout ..., which puts me into a detached head state. I was wondering why. Here's the "dot story":

> git checkout .
# checks out current directory
> git checkout ..
# Checks out parent directory, if in repository.
> git checkout ...
# Puts into detached head state?
> git checkout ....
error: pathspec '....' did not match any file(s) known to git.

Git Solutions


Solution 1 - Git

This is a degenerate form of this syntax, described in the gitrevisions(7) man page:

   <rev1>...<rev2>
       Include commits that are reachable from either <rev1> or <rev2> but
       exclude those that are reachable from both. When either <rev1> or
       <rev2> is omitted, it defaults to HEAD.

Note that last bit, "When either <rev1> or <rev2> is omitted, it defaults to HEAD". That means that writing ... is equivalent to HEAD...HEAD. When used in git checkout this ends up evaluating to the commit id of HEAD. That is, you're just doing:

git checkout HEAD^{commit}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChris JeffersonView Question on Stackoverflow
Solution 1 - GitlarsksView Answer on Stackoverflow