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

Re: Checkout previous branch command not working on ​2.34.1.400

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Dec 6, 2021, 17:17 UTC
Message-ID
<CAPig+cQr27ra4DTjC1gyZO7YdV81Jq5J3s-LcAf+wePP=+n59g@mail.gmail.com>
In-Reply-To
<CAO6o7kKXZg37ydC145yf5uZt+tsKdYADnVfinO0sHAN=cHo-FA@mail.gmail.com>
On Mon, Dec 6, 2021 at 12:04 PM Will Beason <willbeason@google.com> wrote:
Show 5 quoted lines
> I typed "git checkout -"
> error: pathspec '-' did not match any file(s) known to git
>
> I expected the previously-working behavior of switching to previous branch to
> work, but it didn't.

If I recall correctly, for `-` to work it consults the reflog, but if the reflog has been cleared or expired, it won't be able to determine the previous branch. For instance, try this:

    % git init foo
    % cd foo
    % echo data >data
    % git add data
    % git commit -m data
    % git checkout -b other
    % git checkout -
    % git reflog expire --expire=now --all
    % git checkout -
    error: pathspec '-' did not match any file(s) known to git

So, this is probably expected behavior, though the error message isn't very helpful and perhaps could be improved.

Previous: Will BeasonNext: Will Beason
Message 2 of 3 in “Checkout previous branch command not working on ​2.34.1.400”
  1. Will BeasonDec 6, 2021
  2. Eric SunshineDec 6, 2021
  3. Will BeasonDec 6, 2021

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.