I found this section in the git manpage, but it\'s kind of an obfuscated explaination:
As a special case, the \"@{-N}\" syntax for the N-th last branc
That somewhat "obfuscated" explanation is clarified with Git 2.16 (Q1 2018).
@{-N}
in "git checkout @{-N}
" may refer to a detached HEAD state,
but the documentation was not clear about it, which has been fixed.
See commit 75ce149 (27 Nov 2017) by Kaartic Sivaraam (sivaraam).
(Merged by Junio C Hamano -- gitster -- in commit 7065665, 13 Dec 2017)
Doc/checkout
: checking out using@{-N}
can lead to detached state
@{-N}
is a syntax for the N-th last "checkout" and not just the N-th last "branch". Therefore, in some cases usinggit checkout @{-$N}
DOES lead to a "detached HEAD" state.
This can also be ensured by the commit message of 75d6e55 (Documentation:@{-N}
can refer to a commit, 2014-01-19, Git 1.9-rc1) which clearly specifies how@{-N}
can be used to refer not only to a branch but also to a commit.Correct the misleading sentence which states that
@{-N}
doesn't detach HEAD.
The git checkout man page now reads:
You can use the
"@{-N}"
syntax to refer to the N-th last branch/commit checked out using "git checkout" operation.
You may also specify-
which is synonymous to"@{-1}
.