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

8 messages from 2010-10-28 to 2015-09-09. Participants: Todd Wells, Mathias Lafeldt, Santi Béjar, SZEDER Gábor, davilda_, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/25578

## Todd Wells, 2010-10-28 13:09

Subject: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Message-ID: <loom.20101028T150254-457@post.gmane.org>
URL: https://gitlist.dev/e/loom.20101028T150254-457%40post.gmane.org

```
I was using GitX to prepare a commit. Something happened -- I don't 
know what --  and suddenly my branch only had a single commit 
in it that appears to contain all  the files in my tree. So I went to the 
command line and did this:

$ git reset --soft HEAD^ 
fatal: ambiguous argument 'HEAD^': unknown revision or path not 
in the working tree.

When I do 'git log' in this branch, there's only one commit. Now, I 
had many commits in this branch a few minutes ago. I really, 
really, don't want to lose this.

What steps should I take to attempt to recover?

```

## SZEDER Gábor, 2010-10-28 13:41

Subject: Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Message-ID: <20101028134141.GA16149@neumann>
URL: https://gitlist.dev/e/20101028134141.GA16149%40neumann
In-Reply-To: <loom.20101028T150254-457@post.gmane.org>

```
Hi Todd,

On Thu, Oct 28, 2010 at 01:09:08PM +0000, Todd Wells wrote:
> I was using GitX to prepare a commit. Something happened -- I don't 
> know what --  and suddenly my branch only had a single commit 
> in it that appears to contain all  the files in my tree. So I went to the 
> command line and did this:
> 
> $ git reset --soft HEAD^ 
> fatal: ambiguous argument 'HEAD^': unknown revision or path not 
> in the working tree.
> 
> When I do 'git log' in this branch, there's only one commit. Now, I 
> had many commits in this branch a few minutes ago. I really, 
> really, don't want to lose this.
> 
> What steps should I take to attempt to recover?

Take a look at 'gitk yourbranch@{1}' or 'git log yourbranch@{1}'.  If
it looks like your branch's lost history, then you can recover from
this situation with 'git reset --hard yourbranch@{1}'.

You can read up about the details here:
http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#recovering-lost-changes

HtH,
Gábor

```

## Mathias Lafeldt, 2010-10-28 13:42

Subject: Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Message-ID: <4CC97DC8.1010508@debugon.org>
URL: https://gitlist.dev/e/4CC97DC8.1010508%40debugon.org
In-Reply-To: <loom.20101028T150254-457@post.gmane.org>

```
Todd Wells wrote:
> I was using GitX to prepare a commit. Something happened -- I don't 
> know what --  and suddenly my branch only had a single commit 
> in it that appears to contain all  the files in my tree. So I went to the 
> command line and did this:
> 
> $ git reset --soft HEAD^ 
> fatal: ambiguous argument 'HEAD^': unknown revision or path not 
> in the working tree.
> 
> When I do 'git log' in this branch, there's only one commit. Now, I 
> had many commits in this branch a few minutes ago. I really, 
> really, don't want to lose this.
> 
> What steps should I take to attempt to recover?

Check if you can reset your HEAD to a previous state saved in your
(local) reflog.

See section "RefLog Shortnames" in http://progit.org/book/ch6-1.html

-Mathias

```

## Santi Béjar, 2010-10-28 13:42

Subject: Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Message-ID: <AANLkTimbOZwHDez6iAN828AoiqL+EvAV92-WqvhP6ZpP@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimbOZwHDez6iAN828AoiqL%2BEvAV92-WqvhP6ZpP%40mail.gmail.com
In-Reply-To: <loom.20101028T150254-457@post.gmane.org>

```
On Thu, Oct 28, 2010 at 3:09 PM, Todd Wells <ttopwells@gmail.com> wrote:
> I was using GitX to prepare a commit. Something happened -- I don't
> know what --  and suddenly my branch only had a single commit
> in it that appears to contain all  the files in my tree. So I went to the
> command line and did this:
>
> $ git reset --soft HEAD^
> fatal: ambiguous argument 'HEAD^': unknown revision or path not
> in the working tree.
>
> When I do 'git log' in this branch, there's only one commit. Now, I
> had many commits in this branch a few minutes ago. I really,
> really, don't want to lose this.
>
> What steps should I take to attempt to recover?

You could try:

git log -g

which will show you the reflog, a log of recent tip commits of HEAD.
You could also try to see other local branches and their reflog.

If all this fails you can:

git fsck --unreachable

that will output all the unreachable commits/objects, those not in
your branches or reflogs.

Once you have the correct commit you can reset the HEAD to this commit:

git reset HEAD

(or with --hard as necessary).

HTH,
Santi

```

## Santi Béjar, 2010-10-28 14:01

Subject: Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Message-ID: <AANLkTikLOU6HYzDD79eDfPnicQ8X1jTkLGAikAoy3YG-@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikLOU6HYzDD79eDfPnicQ8X1jTkLGAikAoy3YG-%40mail.gmail.com
In-Reply-To: <AANLkTi=QODz+Gf9hwrdu6b900CzuO-BBnF2zmLWOGFpy@mail.gmail.com>

```
Please, don't top post, it's difficult to follow a "reversed" conversation.

On Thu, Oct 28, 2010 at 3:54 PM, Todd Wells <ttopwells@gmail.com> wrote:
> Thanks all of you for your speedy responses.
> git log -g does indeed show my previous commits, for example:
>
> Reflog: HEAD@{0} (Todd Wells <ttopwells@gmail.com>)
> Reflog message: commit: convert mason template to use
> ProjectService.getAllGroups()
> Author: Todd Wells <ttopwells@gmail.com>
> Date:   Thu Oct 28 05:54:22 2010 -0700
>     convert mason template to use ProjectService.getAllGroups()
> commit b80ed79669c56669f05175db9eb9eba4a5fb296e
> // ...etc
>
>
> But I'm not quite sure now if I should do  'git reset --hard yourbranch@{1}'
> or 'git reset HEAD@{0}' or something else.

HEAD@{0} = HEAD

so for sure it is not what you want.

You should first examine the commit history with "git log" or better with gitk:

gitk HEAD@{1}

or

gitk HEAD@{2}

and when you are sure:

git reset --hard HEAD@{n}

(Note that all local changes in the worktree will be lost).

HTH,
Santi

```

## davilda_, 2015-09-09 08:34

Subject: Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Message-ID: <1441787643787-7639207.post@n2.nabble.com>
URL: https://gitlist.dev/e/1441787643787-7639207.post%40n2.nabble.com
In-Reply-To: <loom.20101028T150254-457@post.gmane.org>

```
Hi,
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.
Best regards



--
View this message in context: http://git.661346.n2.nabble.com/fatal-ambiguous-argument-HEAD-unknown-revision-or-path-not-in-the-working-tree-tp5682535p7639207.html
Sent from the git mailing list archive at Nabble.com.

```

## Jeff King, 2015-09-09 09:20

Subject: Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Message-ID: <20150909092042.GC21892@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20150909092042.GC21892%40sigill.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

```

## Junio C Hamano, 2015-09-09 16:24

Subject: Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Message-ID: <xmqq7fnz7e7i.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq7fnz7e7i.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20150909092042.GC21892@sigill.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

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

```
