Git checkout: “@{-N}” syntax

前端 未结 2 802
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 10:37

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

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 11:05

    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 using git 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}.

提交回复
热议问题