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 was getting a corrupt loose object error as well.
I successfully fixed it by going into the directory of the corrupt object. I saw that the users assigned to that object was not my git user's. I don't know how it happened, but I ran a
chown git:git
on that file and then it worked again.This may be a potential fix for some peoples' issues but not necessary all of them.
In answer of @user1055643 missing the last step:
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.
My computer crashed while I was writing a commit message. After rebooting, the working tree was as I had left it and I was able to successfully commit my changes.
However, when I tried to run
git status
I gotUnlike most of the other answers, I wasn't trying to recover any data. I just needed Git to stop complaining about the empty object file.
Overview
The "object file" is git's hashed representation of a real file that you care about. Git thinks it should have a hashed version of
some/file.whatever
stored in.git/object/xx/12345
, and fixing the error turned out to be mostly a matter of figuring out which file the "loose object" was supposed to represent.Details
Possible options seemed to be
Approach 1: Remove the object file
The first thing I tried was just moving the object file
That didn't work - git began complaining about a broken link. On to Approach 2.
Approach 2: Fix the file
Linus Torvalds has a great writeup of how to recover an object file that solved the problem for me. Key steps are summarized here.
This tells you what file the empty object is supposed to be a hash of. Now you can repair it.
After doing this I checked
.git/objects/xx/12345
, it was no longer empty, and git stopped complaining.A garbage collection fixed my problem:
Takes a while to complete, but every loose object and/or corrupted index was fixed.
Runnning
git stash; git stash pop
fixed my problem