Thread (13 messages) flat view 13 messages, 8 authors, 2016-06-15

Re: Undo last commit?

From: Ben Walton <hidden>
Date: 2016-06-15 22:51:29

Excerpts from Mike's message of Sat Jun 18 09:15:49 -0400 2011:

Hi Mike,
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
This command lets you modify the last commit by either adding/removing
changes which you build up with git add or in the case where you've
not staged anything, simply edit the commit message.
% git reset --hard HEAD~1
What you wanted was:

git reset HEAD^
or
git reset HEAD~1

The --hard resets your working tree to match that commit exactly,
throwing away uncommitted changes.  In your case, it threw away the
unstaged changes you'd made and the last commit.  You should be able
to salvage your last commit by:

git reset ORIG_HEAD

The stuff that had never been git added is likely lost.  Because git
had never created an object for those changes, there won't be much to
work with.

You might inspect the output of git reflog to see if that's of any
value, but I don't think it will be in your case.
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.
As always, take a snapshot of the .git directory before doing further
mucking.  Maybe one of the git gurus here has ideas about the trashed
unstaged changes...?

Thanks
-Ben
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help