I'm having big problems with a git repository on my local machine.
I modified a file, ran git status
and the file appeared as modified. I added the file using git add .
and it worked as usual. But when i was about to commit the changes, i got the following error:
error: garbage at end of loose object 'e91ce852822d32e380ed7ddd04c93066e3c600ea'
fatal: object e91ce852822d32e380ed7ddd04c93066e3c600ea is corrupted
By running git cat-file -t e91ce852822d32e380ed7ddd04c93066e3c600ea
, i can see that the object is a tree.
I've seen several solutions on how to repair a corrupt blob or commit, but this is a tree, and I can't find an answer on what could have went wrong, or how to fix it.
Any help appreciated :)
If your git repo is synchronised with an external ressource (Github) and if any solution didn't work, you can re-init your repo
what I've done :
# copy the corrupted .git dir
mv -f .git .gitback
git init
# keep your config file
cp .gitback/config .git/config
# load objects
git pull
It worked. Obviously, it's not a great solution, but it can help
What could have gone wrong is hard to tell, and depends on your Git version and environment.
For example, in the old days, there was a zlib issue with git1.5.1 triggering that kind of message due to a legacyheaders = false
settings.
As for restoring a tree from loose objects, this SO answer "How to recover Git objects damaged by hard disk failure?" illustrates a way to do it, after that a git fsck --full
(as Mark Rushakoff mentions in the comment) has been performed.
git cat-file -t 6c8cae4994b5ec7891ccb1527d30634997a978ee
and check the type of the object.
If the type is tree: you could use 'git ls-tree' to recover the tree from previous backups; then '
git mktree
' to write it again in your current repository.
But that suppose finding those objects either in older packs or in repository backups.
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