How do I undo a `git reset --hard HEAD~1`?

bodacydo

I just made a huge accident. I wanted to undo a local commit and I ran git reset --hard HEAD~1. However I had many uncommited files (about two days of work).

All the uncommited changes have been reset too.

Help!

How do I undo a git reset --hard HEAD~1?

CodeWizard

You can revert ant code you have in your local git folder, whether its was committed or not.

What can be recovered:

  • All commited changes
  • All added items (git add without git commit)
  • All loose blobs (dangling files)

What can't be recovered:

  • Deleted files from the local file system. (You can recover those by using 3rd party tool which scan your drive and recover them)

How to recover:
First run git reflog ro git log -g to verify what did you clean. Then checkout the commit that you wish to recover.
Now you have to recover added but uncommited files. To find those files run git fsck and it will print out the dangling files. use git cat-file -p <SHA1> to print them out to screen and then recover them.

git log -g will display the reflog entry for each of your commit.

Good luck.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related