3

I performed git commit --amend.

I made some changes, but wanted to discard them, so I then performed git reset --hard HEAD, thinking it would go back to the point I amended. It seems to have gone back to the point of the original commit.

There are numerous answers to undoing a git reset --hard HEAD on here, but none specifically that deal with a undoing a reset in this situation (with an amend involved), and I just wanted to make sure I should follow the same pattern before proceeding.

This seems to be the most popular answer: How can I undo git reset --hard HEAD~1?

EDIT

You know what, I'm realizing I've done a couple of --amends today without first doing git add .. What a crappy day. Is there any way to get back the work if I didn't git add .?

Community
  • 1
  • 1
OdieO
  • 6,836
  • 7
  • 56
  • 88
  • Don't think there's any way besides possible file system features (like Windows' shadow copies), if the changes/files have never been in any commit. – Mario Jun 19 '14 at 06:58

1 Answers1

0

If git commit --amend involved any content modification (git add), then the git reset --hard would have worked as expected.

But git commit --amend without any modification would simply modify the commit date (hence changing/SHA1 the commit SHA1)

If those changes were added, this answer shows that git fsck should be able to show you those changes.

A more complete command (in this answer) would be:

git fsck --cache --no-reflogs --lost-found --unreachable  HEAD

More at "Recovering added file after doing git reset --hard HEAD^".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250