Home > OS >  Recover .git folder from an older commit on GitHub
Recover .git folder from an older commit on GitHub

Time:06-15

I usually use git from the GUI in my IDE, but I wanted to do something through the command line. However, this messed up the local .git repository that I had for my project, and now I am unable to commit and push files to my remote repository on GitHub. My project files are still intact and safe, it's only the .git repo that has been messed up.

As my files are still safe, is there a way to recover the repository as it was during an older commit. I have tried downloading the code as it was during an older commit from GitHub, but the .git files is not included. Is is possible to download the repository from GitHub directly.

There were several months of work on my repo, so I really do not want to lose that history. I appreciate any help. Thanks

CodePudding user response:

This may be considering a very manual/hacky way of restoring it but you have several options:

  1. Git clone the repo from GitHub into a new folder. Delete .git in the old folder and cp -r .git from the new folder to the old one. You can then commit the new files as desired.
    Note: By using this method, you lose all your commits, that have not been pushed to github and are only present in the local git repository.

  2. Based on your error message in the commends Error Building Trees Commit Message Invalid Object..., you can consult this previous question facing the same problem as yourself.

  • Related