Repair corrupted Git repository
Solution 1:
My solution for a similar situation was to replace a hash of the damaged object in .git/refs/heads/my-working-branch
with a hash of previous commit (which can be found in .git/logs/HEAD
).
Solution 2:
This just happened to me. I reclone the repository in a new folder and move my latest changes over manually. Low tech, but it works every time. Hopefully you can remember your last changes.
Solution 3:
Try making a backup of the repository and then running git reset --hard HEAD@{1}
to go back to the previous HEAD
and see if this works. It may be just the current HEAD
which is corrupted.
(You should also run fsck
on your disk if you haven't already.)
Solution 4:
The most simple solution for me: You should git clone
in a new folder, then replace the clean new_folder/.git to the old folder (the broken folder). It has worked well for me!
git clone ...(remote) new_folder
mv old_folder/.git old_folder/.git_old
cp -R new_folder/.git old_folder/