{"thread":{"id":"25578","subject":"fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.","startedAt":"2010-10-28T13:09:08Z","lastAt":"2015-09-09T16:24:49Z","messageCount":8,"participants":["Todd Wells","Mathias Lafeldt","Santi Béjar","SZEDER Gábor","davilda_","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"154627","messageId":"loom.20101028T150254-457@post.gmane.org","threadId":"25578","inReplyTo":null,"subject":"fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.","fromName":"Todd Wells","fromEmail":"ttopwells@gmail.com","sentAt":"2010-10-28T13:09:08Z","receivedAt":"2010-10-28T13:09:08Z","isPatch":false,"sender":{"key":"ttopwells@gmail.com","avatar":null},"body":"I was using GitX to prepare a commit. Something happened -- I don't \nknow what --  and suddenly my branch only had a single commit \nin it that appears to contain all  the files in my tree. So I went to the \ncommand line and did this:\n\n$ git reset --soft HEAD^ \nfatal: ambiguous argument 'HEAD^': unknown revision or path not \nin the working tree.\n\nWhen I do 'git log' in this branch, there's only one commit. Now, I \nhad many commits in this branch a few minutes ago. I really, \nreally, don't want to lose this.\n\nWhat steps should I take to attempt to recover?\n"},{"id":"154631","messageId":"20101028134141.GA16149@neumann","threadId":"25578","inReplyTo":"loom.20101028T150254-457@post.gmane.org","subject":"Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2010-10-28T13:41:41Z","receivedAt":"2010-10-28T13:41:41Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi Todd,\n\nOn Thu, Oct 28, 2010 at 01:09:08PM +0000, Todd Wells wrote:\n> I was using GitX to prepare a commit. Something happened -- I don't \n> know what --  and suddenly my branch only had a single commit \n> in it that appears to contain all  the files in my tree. So I went to the \n> command line and did this:\n> \n> $ git reset --soft HEAD^ \n> fatal: ambiguous argument 'HEAD^': unknown revision or path not \n> in the working tree.\n> \n> When I do 'git log' in this branch, there's only one commit. Now, I \n> had many commits in this branch a few minutes ago. I really, \n> really, don't want to lose this.\n> \n> What steps should I take to attempt to recover?\n\nTake a look at 'gitk yourbranch@{1}' or 'git log yourbranch@{1}'.  If\nit looks like your branch's lost history, then you can recover from\nthis situation with 'git reset --hard yourbranch@{1}'.\n\nYou can read up about the details here:\nhttp://www.kernel.org/pub/software/scm/git/docs/user-manual.html#recovering-lost-changes\n\nHtH,\nGábor\n"},{"id":"154628","messageId":"4CC97DC8.1010508@debugon.org","threadId":"25578","inReplyTo":"loom.20101028T150254-457@post.gmane.org","subject":"Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.","fromName":"Mathias Lafeldt","fromEmail":"misfire@debugon.org","sentAt":"2010-10-28T13:42:32Z","receivedAt":"2010-10-28T13:42:32Z","isPatch":false,"sender":{"key":"misfire@debugon.org","avatar":"https://avatars.githubusercontent.com/u/158074?v=4"},"body":"Todd Wells wrote:\n> I was using GitX to prepare a commit. Something happened -- I don't \n> know what --  and suddenly my branch only had a single commit \n> in it that appears to contain all  the files in my tree. So I went to the \n> command line and did this:\n> \n> $ git reset --soft HEAD^ \n> fatal: ambiguous argument 'HEAD^': unknown revision or path not \n> in the working tree.\n> \n> When I do 'git log' in this branch, there's only one commit. Now, I \n> had many commits in this branch a few minutes ago. I really, \n> really, don't want to lose this.\n> \n> What steps should I take to attempt to recover?\n\nCheck if you can reset your HEAD to a previous state saved in your\n(local) reflog.\n\nSee section \"RefLog Shortnames\" in http://progit.org/book/ch6-1.html\n\n-Mathias\n"},{"id":"154629","messageId":"AANLkTimbOZwHDez6iAN828AoiqL+EvAV92-WqvhP6ZpP@mail.gmail.com","threadId":"25578","inReplyTo":"loom.20101028T150254-457@post.gmane.org","subject":"Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2010-10-28T13:42:45Z","receivedAt":"2010-10-28T13:42:45Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"On Thu, Oct 28, 2010 at 3:09 PM, Todd Wells <ttopwells@gmail.com> wrote:\n> I was using GitX to prepare a commit. Something happened -- I don't\n> know what --  and suddenly my branch only had a single commit\n> in it that appears to contain all  the files in my tree. So I went to the\n> command line and did this:\n>\n> $ git reset --soft HEAD^\n> fatal: ambiguous argument 'HEAD^': unknown revision or path not\n> in the working tree.\n>\n> When I do 'git log' in this branch, there's only one commit. Now, I\n> had many commits in this branch a few minutes ago. I really,\n> really, don't want to lose this.\n>\n> What steps should I take to attempt to recover?\n\nYou could try:\n\ngit log -g\n\nwhich will show you the reflog, a log of recent tip commits of HEAD.\nYou could also try to see other local branches and their reflog.\n\nIf all this fails you can:\n\ngit fsck --unreachable\n\nthat will output all the unreachable commits/objects, those not in\nyour branches or reflogs.\n\nOnce you have the correct commit you can reset the HEAD to this commit:\n\ngit reset HEAD\n\n(or with --hard as necessary).\n\nHTH,\nSanti\n"},{"id":"154632","messageId":"AANLkTikLOU6HYzDD79eDfPnicQ8X1jTkLGAikAoy3YG-@mail.gmail.com","threadId":"25578","inReplyTo":"AANLkTi=QODz+Gf9hwrdu6b900CzuO-BBnF2zmLWOGFpy@mail.gmail.com","subject":"Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2010-10-28T14:01:45Z","receivedAt":"2010-10-28T14:01:45Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"Please, don't top post, it's difficult to follow a \"reversed\" conversation.\n\nOn Thu, Oct 28, 2010 at 3:54 PM, Todd Wells <ttopwells@gmail.com> wrote:\n> Thanks all of you for your speedy responses.\n> git log -g does indeed show my previous commits, for example:\n>\n> Reflog: HEAD@{0} (Todd Wells <ttopwells@gmail.com>)\n> Reflog message: commit: convert mason template to use\n> ProjectService.getAllGroups()\n> Author: Todd Wells <ttopwells@gmail.com>\n> Date:   Thu Oct 28 05:54:22 2010 -0700\n>     convert mason template to use ProjectService.getAllGroups()\n> commit b80ed79669c56669f05175db9eb9eba4a5fb296e\n> // ...etc\n>\n>\n> But I'm not quite sure now if I should do  'git reset --hard yourbranch@{1}'\n> or 'git reset HEAD@{0}' or something else.\n\nHEAD@{0} = HEAD\n\nso for sure it is not what you want.\n\nYou should first examine the commit history with \"git log\" or better with gitk:\n\ngitk HEAD@{1}\n\nor\n\ngitk HEAD@{2}\n\nand when you are sure:\n\ngit reset --hard HEAD@{n}\n\n(Note that all local changes in the worktree will be lost).\n\nHTH,\nSanti\n"},{"id":"269641","messageId":"1441787643787-7639207.post@n2.nabble.com","threadId":"25578","inReplyTo":"loom.20101028T150254-457@post.gmane.org","subject":"Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.","fromName":"davilda_","fromEmail":"vattolou@jam-difus.com","sentAt":"2015-09-09T08:34:03Z","receivedAt":"2015-09-09T08:34:03Z","isPatch":false,"sender":{"key":"vattolou@jam-difus.com","avatar":null},"body":"Hi,\ni'm new with git and i just want to cancel a commit. I just do git add and\ngit commit.\nHow can i canceled a commit in my case.\nBest regards\n\n\n\n--\nView 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\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"269644","messageId":"20150909092042.GC21892@sigill.intra.peff.net","threadId":"25578","inReplyTo":"1441787643787-7639207.post@n2.nabble.com","subject":"Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-09-09T09:20:42Z","receivedAt":"2015-09-09T09:20:42Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Sep 09, 2015 at 01:34:03AM -0700, davilda_ wrote:\n\n> i'm new with git and i just want to cancel a commit. I just do git add and\n> git commit.\n> How can i canceled a commit in my case.\n\nUsually with \"git reset HEAD^\". But I'm guessing from your subject line\nthat you tried that, and it did not work because this commit is the\n_only_ commit in your repository (and \"HEAD^\", which means \"the parent\ncommit of HEAD\", does not make any sense, as there is no parent).\n\nAnnoyingly, I don't think there is an easy way with the current tools to\nhandle this corner case (you want to not reset to a commit, but back to\nthe \"unborn branch\" state).\n\nThe \"simplest\" way to do that is:\n\n  rm .git/refs/heads/master\n\nbut that is not guaranteed to work in future versions of git, and I\nwouldn't recommend it in general.\n\nProbably a better workflow is to create the commit state you _do_ want\n(change files, \"git add\" them, etc), and then run \"git commit --amend\"\nto replace the bad commit.\n\n-Peff\n"},{"id":"269660","messageId":"xmqq7fnz7e7i.fsf@gitster.mtv.corp.google.com","threadId":"25578","inReplyTo":"20150909092042.GC21892@sigill.intra.peff.net","subject":"Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-09-09T16:24:49Z","receivedAt":"2015-09-09T16:24:49Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> The \"simplest\" way to do that is:\n>\n>   rm .git/refs/heads/master\n>\n> but that is not guaranteed to work in future versions of git, and I\n> wouldn't recommend it in general.\n\nYeah, \"git checkout -b\" has a stronger sibling \"git checkout -B\"\n(i.e. I know that the named branch already exists, so this is not a\nrequest to create a new one, but to repoint that existing one), but\nthere is no analogue for \"git checkout --orphan\".  That could be\nworked around with something like this though:\n\n    $ git checkout --orphan hu\n    $ git branch -D master\n    $ git checkout --orphan master\n\nAs I agree with your \"amending is better\", I do not think allowing\nan easier access to such a feature is urgent or important, though.\n\n> Probably a better workflow is to create the commit state you _do_ want\n> (change files, \"git add\" them, etc), and then run \"git commit --amend\"\n> to replace the bad commit.\n"}]}