From: Jeff King <peff@peff.net>
To: davilda_ <vattolou@jam-difus.com>
Cc: git@vger.kernel.org
Subject: Re: fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
Date: Wed, 9 Sep 2015 05:20:42 -0400 [thread overview]
Message-ID: <20150909092042.GC21892@sigill.intra.peff.net> (raw)
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
next prev parent reply other threads:[~2015-09-09 9:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-28 13:09 fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree Todd Wells
2010-10-28 13:41 ` SZEDER Gábor
2010-10-28 13:42 ` Mathias Lafeldt
2010-10-28 13:42 ` Santi Béjar
[not found] ` <AANLkTi=QODz+Gf9hwrdu6b900CzuO-BBnF2zmLWOGFpy@mail.gmail.com>
2010-10-28 14:01 ` Santi Béjar
2015-09-09 8:34 ` davilda_
2015-09-09 9:20 ` Jeff King [this message]
2015-09-09 16:24 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2007-06-08 10:08 fatal: ambiguous argument 'HEAD': " Thomas Glanzmann
2007-06-08 10:15 ` Junio C Hamano
2007-06-08 10:21 ` Thomas Glanzmann
2007-06-08 10:33 ` Junio C Hamano
2007-06-08 10:38 ` Thomas Glanzmann
2007-06-08 10:27 ` Junio C Hamano
2007-06-10 8:54 ` carbonated beverage
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150909092042.GC21892@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=vattolou@jam-difus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).