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:
Git clone the repo from GitHub into a new folder. Delete
.gitin the old folder andcp -r .gitfrom 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 localgitrepository.Based on your error message in the commends
Error Building TreesCommit Message Invalid Object..., you can consult this previous question facing the same problem as yourself.
