What does git checkout ... do do?

Sometimes I accidentally write git checkout ... which puts me in a separate head state. I was wondering why. Here's the point-to-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. 
+54
git
Sep 07 '17 at 16:31 on
source share
1 answer

This is a degenerate form of this syntax described on 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 the last bit: "If <rev1> or <rev2> not specified, HEAD is used by default." This means that the record ... equivalent to HEAD...HEAD . When used in git checkout this ends with evaluating the HEAD commit identifier. That is, you just do:

 git checkout HEAD^{commit} 
+48
Sep 07 '17 at 16:50
source share



All Articles