0

I intended to git reset --hard to the last commit I made but I accidentally went back to the commit before that. Is there anyway to undo this.

This was the sequence of events: 1. I pulled from a common repo and made some changes and committed them (SHA1). I made more changes and committed them too(SHA2). Then I made some more changes but never committed them I just wanted to go back to SHA2. Instead I reset to SHA1. Now, all my changes are lost. Can I undo the last reset and get to SHA2?

What I mean is when I did a git log:

"SHA2" - HEAD
 Jun 26
 some comment -1

 "SHA1" - Origin
  Jun 25
  some comment -2

I reset to SHA1 instead of to SHA2. Can I undo my reset --hard

Hitch
  • 17
  • 1
  • 6
  • If you still have the value of “SHA2” somewhere, you can also just reset there directly: `git reset --hard SHA2`. – poke Jun 28 '15 at 14:44
  • I tried doing that, but I still don't see any of my earlier changes. They seem to have been lost. – Hitch Jun 28 '15 at 14:49
  • Which earlier changes are you referring to? The uncommitted ones you did after SHA2? Uncommitted changes are thrown away when doing `git reset --hard` and unless you at least added them to the index, there’s no way to get them back. – poke Jun 28 '15 at 14:51

1 Answers1

0

I'd look at git reflog. It keeps track of many of your local changes, and can be used to recover lost commits (assuming clean-up hasn't occured)

mjgpy3
  • 8,597
  • 5
  • 30
  • 51