Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in DevOps and Agile by (19.4k points)

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?

1 Answer

0 votes
by (27.5k points)

Execute the following commands from the parent directory above your repo:

Note: Replace 'foo' with the name of your project folder

1. Create a backup of the corrupt directory:

cp -R foo foo-backup

2. Now make a new clone of the remote repository to a new directory:

git clone [email protected]:foo foo-newclone

3. Delete the corrupt .git subdirectory:

rm -rf foo/.git

4. Move the newly cloned .git subdirectory into foo:

mv foo-newclone/.git foo

5. Delete the rest of the temporary new clone:

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 statuscommit, pull, push, etc. work again as they should.

Browse Categories

...