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
Jeff King <peff@peff.net>
Date
Sep 9, 2015, 09:20 UTC
Message-ID
<20150909092042.GC21892@sigill.intra.peff.net>
In-Reply-To
<1441787643787-7639207.post@n2.nabble.com>
On Wed, Sep 09, 2015 at 01:34:03AM -0700, davilda_ wrote:
> i'm new with git and i just want to cancel a commit. I just do git add and
> git commit.
> How can i canceled a commit in my case.

Usually with "git reset HEAD^". But I'm guessing from your subject line that you tried that, and it did not work because this commit is the _only_ commit in your repository (and "HEAD^", which means "the parent commit of HEAD", does not make any sense, as there is no parent).

Annoyingly, I don't think there is an easy way with the current tools to handle this corner case (you want to not reset to a commit, but back to the "unborn branch" state).

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.

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.

-Peff
Previous: davilda_Next: Junio C Hamano
Message 6 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.