I accidentally git reset --hard in the first initial commit, how to restore it back?

68 views Asked by At

I noticed error with the initial commit. So I ran 'git reset --hard origin/master' command. After this command it deleted all the files locally and didn't see anything, How can I restore all files

1

There are 1 answers

0
Krishnakumar Natarajan On

Use git reflog to find the hash correspinding to your "initial commit".

Then git reset --hard <hash>. This will restore your files same as the one you had in your initial commit.

Example:

$ git reflog
42115cd HEAD@{0}: commit: reset --hard HEAD^: updating HEAD
ab92d4d HEAD@{1}: commit: initial commit
$ git reset --hard ab92d4d

After this your files should be restored.

Here is the answer thread in detailed,

How can I undo git reset --hard HEAD~1?