{"thread":{"id":"47244","subject":"Can @{-N} always be used where a branch name is expected?","startedAt":"2017-11-19T18:09:16Z","lastAt":"2017-11-19T18:09:16Z","messageCount":1,"participants":["Kaartic Sivaraam"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"332866","messageId":"38b4b665-18c4-5c95-f142-aedf33bc1b5c@gmail.com","threadId":"47244","inReplyTo":null,"subject":"Can @{-N} always be used where a branch name is expected?","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-11-19T18:09:04Z","receivedAt":"2017-11-19T18:09:16Z","isPatch":false,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"I was recently digging to find if there is any special syntax accepted \nfor <oldbranch> in \"git branch -m <oldbranch> <newbranch>\" other than \nthe plain branch name. I discovered the @{-N} notation. I was trying to \nplay around with it and found that it didn't work as guaranteed by the \nlast sentence  of the following paragraph in the \"check-ref-format\" \ndocumentation,\n\n\n     With the --branch option, it expands the “previous branch syntax” \n@{-n}. For example, @{-1} is a way to refer the last branch you were on.\n     This option should be used by porcelains to accept this syntax \nanywhere a branch name is expected, so they can act as if you typed the\n     branch name.\n\n\nIn particular the following case doesn't work,\n\ngit init test &&\ncd test &&\necho \"Hello\" >file &&\ngit add file &&\ngit commit -m \"Initial commit that will be checked out\" &&\necho \"Hello world\" >file &&\ngit commit file -m \"Second commit\" &&\ngit checkout HEAD^ &&\ngit checkout - &&\ngit branch -m @{-1} initial-commit\n\n\nIt failed with an error,\n\nerror: refname refs/heads/d21e72600673c670b3ae803488d0cebfa949e4c3 not found\nfatal: Branch rename failed\n\n\nThen I digged into why it didn't work to discover that @{-N}  just \nexpands to a valid checkout and not a valid \"branch name\". So, the \ndocumentation  guaranteeing that \"@{-N} acts as if you typed the branch \nname\" seems wrong.  That makes me think that we should avoid misleading \nthe user in the \"check-ref-format\" documentation.\n\nSo, should we update the 'check-ref-format' doc or am I missing something?\n\n---\nKaartic\n"}]}