Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace corrupt Git objects with new ones created from my files, which are fine

Tags:

git

My app, in my filesystem, works just fine. All tests pass.

I'm a sole developer, using Git mostly to use Heroku as well as for backup.

Git has stopped working because of corrupt objects.

I'm getting errors that look like this:

steven-nobles-imac-200:drominay steven$ git push heroku master
error: inflate: data stream error (invalid distance too far back)
fatal: object 990ad2766afa2e2002eea265225ad160e73eacd2 is corrupted
error: pack-objects died with strange error

(And many other errors, all citing corrupted objects.)

How do I get Git to throw out the corrupt objects and replace them with new objects built from the working copy of my app?

Git init didn't solve the problem.

Thanks!

like image 648
steven_noble Avatar asked Feb 02 '10 11:02

steven_noble


1 Answers

You need to use git-fsck. The manual has details, but the gist is that git-fsck will make sure that the repository is internally consistent and list the missing objects, then you may use git hash-object -w <correct-file> to put the file given into the repository. If the file given to hash-object really is the one that was corrupt, your repository is now complete again :).

Updated to add: Git repair does the same things, but automagically :).

like image 89
Andrew Aylett Avatar answered Oct 05 '22 07:10

Andrew Aylett