开发者

How to restore a corrupted git repository?

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:

$开发者_JS百科 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!


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 :).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜