I lost my last commit because I accidentally ran \"git reset --hard HEAD^\". Note: I didn\'t want to put the \"^\" at the end.
Is there any way to get it back? It wa
git makes it really easy to go back to a prior state and works very hard to prevent you from losing any data you've committed. It's this reason you should commit often. I've got a command git trash
that does that git reset --hard
state, but after writing a commit so that I can undo the hard reset if I need.
For the most recent state (i.e. your exact case), just do git reset --hard ORIG_HEAD
to undo what you just did.
You can do a time-based reset: git reset --hard '@{5 minutes ago}'
to put yourself in a prior state based on time (there are lots of options you can use, for example, git reset --hard '@{yesterday}'
to pretend today never happened).
Otherwise, browse the git reflog
output to find the thing before the action you feel put you in a bad state and reset to that.