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

Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 9, 2015, 16:24 UTC
Message-ID
<xmqq7fnz7e7i.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20150909092042.GC21892@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 6 quoted lines
> The "simplest" way to do that is:
>
>   rm .git/refs/heads/master
>
> but that is not guaranteed to work in future versions of git, and I
> wouldn't recommend it in general.

Yeah, "git checkout -b" has a stronger sibling "git checkout -B" (i.e. I know that the named branch already exists, so this is not a request to create a new one, but to repoint that existing one), but there is no analogue for "git checkout --orphan". That could be worked around with something like this though:

    $ git checkout --orphan hu
    $ git branch -D master
    $ git checkout --orphan master

As I agree with your "amending is better", I do not think allowing an easier access to such a feature is urgent or important, though.

> Probably a better workflow is to create the commit state you _do_ want
> (change files, "git add" them, etc), and then run "git commit --amend"
> to replace the bad commit.
Previous: Jeff KingNext: Santi Béjar
Message 7 of 8 in “fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.”
  1. Todd WellsOct 28, 2010
  2. SZEDER GáborOct 28, 2010
  3. Mathias LafeldtOct 28, 2010
  4. Santi BéjarOct 28, 2010
  5. davilda_Sep 9, 2015
  6. Jeff KingSep 9, 2015
  7. Junio C HamanoSep 9, 2015
  8. Santi BéjarOct 28, 2010

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.