From: Mike <xandrani@gmail.com>
To: git@vger.kernel.org
Subject: Undo last commit?
Date: Sat, 18 Jun 2011 14:15:49 +0100 [thread overview]
Message-ID: <BANLkTinWujKYvx_fh2iBDOdMbywqzfgwUA@mail.gmail.com> (raw)
Hi fellow gitters,
I have performed a 'git commit' on all 'added' files by mistake and
now I want to undo this commit to return to the original state. Here's
a more detailed description:
1. I did a 'git status' and there were files which I had 'added' ready
for a commit. There were also some changes that had not been 'added'
yet. See below:
% git status
# On branch master
# Your branch is ahead of 'origin/master' by 7 commits.
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: cgi-bin/example1.php
# modified: cgi-bin/example2.php
# modified: example3.php
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: cgi-bin/example4.php
# modified: example5.php
#
2. I accidentally did a commit for ALL files because I forgot to
specify the filename at the end of the commit.
e.g. instead of 'commit -m "commit message" example3.php' I did
'commit -m "commit message"'.
3. I googled the problem and it seems everyone has a different way of
doing this. (Maybe git is too confusing if everyone has different
methods that all work slightly differently!?). Anyway I executed this
command:
% git commit --amend
But I aborted this by exiting my text editor.
4. I then tried:
% git reset --hard HEAD~1
5. However now when I do a 'git status' none of the files that were
original listed are there. A git status now gives this:
# On branch master
# Your branch is ahead of 'origin/master' by 7 commits.
#
nothing to commit (working directory clean)
Any ideas how to rectify this issue? I presume the 'git commit
--amend' just changes the commit message? I daren't try anything else
myself in case I make matters worse.
Mike
next reply other threads:[~2011-06-18 13:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-18 13:15 Mike [this message]
2011-06-18 13:43 ` Undo last commit? Ben Walton
2011-06-18 13:48 ` Ramkumar Ramachandra
2011-06-18 13:54 ` Jakub Narebski
2011-06-19 0:37 ` Jonathan Nieder
2011-06-19 10:37 ` Jakub Narebski
2011-06-20 12:08 ` Massimo Manca
2011-06-28 13:57 ` Holger Hellmuth
2011-06-28 14:31 ` Mike
2011-06-30 4:50 ` Ramkumar Ramachandra
2011-06-30 18:38 ` Jonathan Nieder
2011-06-30 19:48 ` Mike
2011-06-30 17:29 ` Junio C Hamano
2012-02-11 18:19 ` Neal Kreitzinger
[not found] ` <CAHK-92oMc62O0S8Bxt6+uxobE+kg5wOeRDoOsHWvvenXaXmZGQ@mail.gmail.com>
2012-02-11 22:07 ` Jakub Narebski
2012-02-11 22:29 ` Jonathan Nieder
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=BANLkTinWujKYvx_fh2iBDOdMbywqzfgwUA@mail.gmail.com \
--to=xandrani@gmail.com \
--cc=git@vger.kernel.org \
/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).