threads / discuss / 25578

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

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

## tl;dr

8 messages between Oct 28, 2010 and Sep 9, 2015.

replies: 7people: 7as markdown or json

Todd Wells· Oct 28, 2010, 13:09 UTC · lore

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· Oct 28, 2010, 13:41 UTC · re: Todd Wells · lore

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

Hi Todd,
On Thu, Oct 28, 2010 at 01:09:08PM +0000, Todd Wells wrote:
Show 14 quoted lines
> 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· Oct 28, 2010, 13:42 UTC · re: Todd Wells · lore

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

Todd Wells wrote:
Show 14 quoted lines
> 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· Oct 28, 2010, 13:42 UTC · re: Todd Wells · lore

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

On Thu, Oct 28, 2010 at 3:09 PM, Todd Wells <ttopwells@gmail.com> wrote:
Show 14 quoted lines
> 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

davilda_· Sep 9, 2015, 08:34 UTC · re: Todd Wells · lore

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

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· Sep 9, 2015, 09:20 UTC · re: davilda_ · lore

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

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· Sep 9, 2015, 16:24 UTC · re: Jeff King · lore

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

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.
Santi Béjar· Oct 28, 2010, 14:01 UTC · lore

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

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:
Show 15 quoted lines
> 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

← back to recent threads