Restoring a Deleted Commit in git
Not often needed. But this tutorial will show you how to restore a commit that you have deleted in Git.
Suppose we have two commits so far…
And then suppose, we have deleted the “add new file” commit by running …
git reset –hard HEAD~
And are left with only the first commit.
Now we want to restore the commit we just deleted.
1. List all the dangling commits with “git fsck –lost-found”. It stands for “file system consistency check”:
2. Get info on the SHA’s by “git reflog”.
3. Once you have the SHA, restore it with …
git merge 7176753
Note: this may not work if you had run “git gc”