Search code examples
gitgithubdata-recovery

Github Recovery


I was trying to recover a single file from an old commit in my git repository through the command line and I accidentally reverted the entire commit to my very first commit (this was made in December) and now I can't see any other git pushes?

Have I just lost all of my data or is there a way to restore it?


Solution

  • As this site states, you can do the following:

    • Execute git reflog and look for a commit that contains your file. Remember the commit hash.
    • Checkout the file using git checkout <commit hash> <path/to/file> or merge the commit with your head (git merge <commit>).

    See the docs for git reflog, git checkout and git merge for details.