Whenever I pull from my remote, I get the following error about compression. When I run the manual compression, I get the same:
$ git gc
error: Could not read 3813783126d41a3200b35b6681357c213352ab31
fatal: bad tree object 3813783126d41a3200b35b6681357c213352ab31
error: failed to run repack
Does anyone know, what to do about that?
From cat-file I get this:
$ git cat-file -t 3813783126d41a3200b35b6681357c213352ab31
error: unable to find 3813783126d41a3200b35b6681357c213352ab31
fatal: git cat-file 3813783126d41a3200b35b6681357c213352ab31: bad file
And from git fsck I get this ( don't know if it's actually related):
$ git fsck
error: inflate: data stream error (invalid distance too far back)
error: corrupt loose object '45ba4ceb93bc812ef20a6630bb27e9e0b33a012a'
fatal: loose object 45ba4ceb93bc812ef20a6630bb27e9e0b33a012a (stored in .git/objects/45/ba4ceb93bc812ef20a6630bb27e9e0b33a012a) is corrupted
Can anyone help me decipher this?
I had the same problem (don't know why).
This fix requires access to an uncorrupted remote copy of the repository, and will keep your locally working copy intact.
But it has some drawbacks:
Execute these commands from the parent directory above your repo (replace 'foo' with the name of your project folder):
cp -R foo foo-backup
git clone [email protected]:foo foo-newclone
rm -rf foo/.git
mv foo-newclone/.git foo
rm -rf foo-newclone
On Windows you will need to use:
copy
instead of cp -R
rmdir /S
instead of rm -rf
move
instead of mv
Now foo has its original .git
subdirectory back, but all the local changes are still there. git status
, commit
, pull
, push
, etc. work again as they should.
Your best bet is probably to simply re-clone from the remote repository (i.e., GitHub or other). Unfortunately you will lose any unpushed commits and stashed changes, however your working copy should remain intact.
First make a backup copy of your local files. Then do this from the root of your working tree:
rm -fr .git
git init
git remote add origin [your-git-remote-url]
git fetch
git reset --mixed origin/master
git branch --set-upstream-to=origin/master master
Then commit any changed files as necessary.
Working on a VM, in my notebook, battery died, got this error;
error: object file .git/objects/ce/theRef is empty error: object file .git/objects/ce/theRef is empty fatal: loose object theRef (stored in .git/objects/ce/theRef) is corrupt
I managed to get the repo working again with only 2 commands and without losing my work (modified files/uncommitted changes)
find .git/objects/ -size 0 -exec rm -f {} \;
git fetch origin
After that I ran a git status
, the repo was fine and there were my changes (waiting to be committed, do it now..).
git version 1.9.1
Remember to backup all changes you remember, just in case this solution doesn't works and a more radical approach is needed.
Looks like you have a corrupt tree object. You will need to get that object from someone else. Hopefully they will have an uncorrupted version.
You could actually reconstruct it if you can't find a valid version from someone else by guessing at what files should be there. You may want to see if the dates & times of the objects match up to it. Those could be the related blobs. You could infer the structure of the tree object from those objects.
Take a look at Scott Chacon's Git Screencasts regarding git internals. This will show you how git works under the hood and how to go about doing this detective work if you are really stuck and can't get that object from someone else.
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