fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
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?
Hi Todd,
Quoted 9 lines · Todd Wells
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.
Quoted 5 lines
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
Quoted 9 lines · Todd Wells
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.
Quoted 5 lines
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
Quoted 9 lines · Todd Wells
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.
Quoted 5 lines
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
Please, don't top post, it's difficult to follow a "reversed" conversation.
Quoted 13 lines · Todd Wells
Thanks all of you for your speedy responses.
git log -g does indeed show my previous commits, for example:Reflog: HEAD@{0} (Todd Wells <[email protected]>) Reflog message: commit: convert mason template to use
ProjectService.getAllGroups()
Author: Todd Wells <[email protected]>
Date: Thu Oct 28 05:54:22 2010 -0700
convert mason template to useProjectService.getAllGroups()commitb80ed79669c56669f05175db9eb9eba4a5fb296e
// ...etc
Quoted 2 lines
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
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.
Quoted 3 lines · davilda_
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
Quoted 6 lines · Jeff King
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 masterAs I agree with your "amending is better", I do not think allowing an easier access to such a feature is urgent or important, though.
Quoted 3 lines
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.