git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Undo last commit?

From
Ben Walton <bwalton@artsci.utoronto.ca>
Date
Jun 18, 2011, 13:43 UTC
Message-ID
<1308404291-sup-8978@pinkfloyd.chass.utoronto.ca>
In-Reply-To
<BANLkTinWujKYvx_fh2iBDOdMbywqzfgwUA@mail.gmail.com>
Excerpts from Mike's message of Sat Jun 18 09:15:49 -0400 2011:
Hi Mike,
Show 6 quoted lines
> 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

Previous: MikeNext: Ramkumar Ramachandra
Message 2 of 16 in “Undo last commit?”
  1. MikeJun 18, 2011
  2. Ben WaltonJun 18, 2011
  3. Ramkumar RamachandraJun 18, 2011
  4. Jakub NarebskiJun 18, 2011
  5. Jonathan NiederJun 19, 2011
  6. Jakub NarebskiJun 19, 2011
  7. Massimo MancaJun 20, 2011
  8. Holger HellmuthJun 28, 2011
  9. MikeJun 28, 2011
  10. Ramkumar RamachandraJun 30, 2011
  11. Jonathan NiederJun 30, 2011
  12. MikeJun 30, 2011
  13. Junio C HamanoJun 30, 2011
  14. Neal KreitzingerFeb 11, 2012
  15. Jakub NarebskiFeb 11, 2012
  16. Jonathan NiederFeb 11, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.