0

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

FireTheLost
  • 131
  • 7
  • Can you include the error log from trying to commit or push files? Maybe we can solve the problem by fixing `.git`. – Mime Jun 15 '22 at 08:04
  • This is what it's saying (from CLion): 0 file committed, 3 files failed to commit: commit message invalid object 100644 0a743e97ec9a19a4522c508d53cfcf500207500d for 'file/path.cpp' invalid object 100644 0a743e97ec9a19a4522c508d53cfcf500207500d for 'file/path.cpp' Error building trees – FireTheLost Jun 15 '22 at 08:07
  • Does this answer help you? https://stackoverflow.com/a/38603911/11688567 – Mime Jun 15 '22 at 08:14
  • 1
    did you by any chance run your cli actions as root (linux) or from an elevated privileges console (windows) ? can you check the access rights on files within your `.git/` directory ? – LeGEC Jun 15 '22 at 08:15

1 Answers1

1

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.

Mime
  • 1,142
  • 1
  • 9
  • 20