Re: Undo last commit?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]