12

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:

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!

Community
  • 1
  • 1
greydet
  • 5,509
  • 3
  • 31
  • 51
  • 2
    The first step here is to check your filesystems. That error is strange. Did you `fsck` or whatever your OS has for that? And do a **BACKUP** before you do anything else. – Mat Oct 06 '11 at 21:40
  • Nearly all answers assume one can simply re-clone from some uncorruptible remote origin. Here's the problem... What if you **are** the origin, and you're corrupted? Right. So, here: `git-repair` is a program that will run `git fsck` and try pretty hard to fix any problems it encounters. https://git-repair.branchable.com/ It seems quite capable, and though you might end up having to copy (if you can!) objects from a backup (you have a backup, right?), it should save you a lot of time by salvaging whatever it can and leaving you the real work, not lots of automatable tasks. No affiliation, etc. – underscore_d Dec 21 '16 at 01:03

2 Answers2

2

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

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • 1
    Sure I could start over a new clone, hopefully I am not too far from my svn trunk (my local repo is a git-svn clone). But I was wondering if this kind of issue can be recovered and what was the origin of it to avoid reproducing it in the future. – greydet Oct 09 '11 at 10:26
2

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

Parris
  • 17,833
  • 17
  • 90
  • 133