My Git repository got corrupted after a couple of hard reboots due to power supply issues and now I'm unable to fix it (I was in the middle of staging some files at the last power failure):
$ git status
fatal: failed to read object 3d18855708b0f127d40c13c679559d7679228b69: Invalid argument
$ git fsck
fatal: failed to read object 24377c609184c192f3f3c1733bac7115c1080758: Invalid argument
$ git branch -a
(...works, lists branches...)
$ git checkout someotherbranch
fatal: failed to read object 3d18855708b0f127d40c13c679559d7679228b69: Invalid argument
$ git log
fatal: failed to read object 3d18855708b0f127d40c13c679559d7679228b69: Invalid argument
$ git log someotherbranch
(...works, shows commits...)
So, as you can see, my current branch is pretty screwed up, and I don't seem to be able to fix it. What can I try to repair this?
if your local . git folder gets corrupted, that corruption won't be propagated upstream to the server, so you should always be able to get a clean copy, minus your most recent changes. as for your question, most of the files in . git are not changed when you add a new commit.
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
).
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With