Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore a corrupted git repository?

Tags:

git

After a hard reset of my laptop that freezed after a git commit, I have the following error when I enter any command on my git repository:

$ git status 
fatal: failed to read object de02e6d5cd7823ea788429a33583bede09221163: Invalid argument

Is there anyway to recover my git repository?

I did not find a solution from the two following questions:

  • How do you restore a corrupted object in a git repository (for newbies)?
  • How to recover Git objects damaged by hard disk failure?

EDIT: I did not found what caused the corruption of my git repository nor any solution to restore it... I finally started over a new clone from my SVN repository!

like image 857
greydet Avatar asked Oct 06 '11 21:10

greydet


2 Answers

For me, none of the above answers worked. I just re-cloned my git repo and all was well. Before cloning, I opened up all the files that were changed and just overwrote them after the pull.

That's why you should commit often :).

like image 167
Parris Avatar answered Oct 04 '22 18:10

Parris


Did you push your repository to anywhere like github or bitbucket recently? You could get another clone and copy the objects directory.

Otherwise:

See how many of these run:

git fsck
git branch -a
git branch -a | xargs -n 1 git log -1 
git reflog

With the reflog, see which one of those you can do a successful log from. hopefully it's just your latest commit that's corrupt or one of it's trees.

Hope this helps

like image 39
Adam Dymitruk Avatar answered Oct 04 '22 18:10

Adam Dymitruk