git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git checkout -

From
Todd Zullinger <tmz@pobox.com>
Date
Jan 4, 2020, 05:17 UTC
Message-ID
<20200104051741.GJ9927@pobox.com>
In-Reply-To
<20200104004826.GC130883@google.com>
Hi,
Jonathan Nieder wrote:
Show 18 quoted lines
> Hi,
> 
> François WAUQUIER wrote:
> 
>> $ git checkout -
>>
>> I often use this command to go back to previous branch from my history.
>> It is quite natural as it uses the same syntax as “cd -“
>>
>> But i found out it is not documented in
>> https://git-scm.com/docs/git-checkout/2.24.0
>> I report this to help others to discover this time saving command.
> 
> Thanks for reporting!
> 
> Ideas for what the documentation should say about it?  (Bonus points
> if it comes in the form of a patch against Documentation/git-checkout.txt.
> ;-)  See [1] for more about how that works.)

Not to say that it can't possibly be improved, but it is mentioned in the git-checkout docs here[1]. The second paragraph in that section says:

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

This is also in the git-switch documentation, where it might be easier to find, as it's very close to the beginning of git-switch's man page, in the "<start-point>" entry of the OPTIONS section[2].

Being easy to miss in the git-checkout documentation might make Duy smile; it shows the benefit of splitting some of the many features of 'checkout' to the 'switch' command. :)

[1] https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt-ltbranchgt [2] https://git-scm.com/docs/git-switch#Documentation/git-switch.txt-ltstart-pointgt

-- 
Todd
Previous: Jonathan Nieder
Message 3 of 3 in “”
  1. François WAUQUIERJan 3, 2020
  2. Jonathan NiederJan 4, 2020
  3. Todd ZullingerJan 4, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.