20

Is there any way I can repair my repository with commit history in tact.

 # git log
fatal: object 01aeb2bf2e93b238f0e0422816b3e55518321ae7 is corrupted

From reading the link below it looks like I'll have zap it and start over.

http://www.miek.nl/s/7e76eadefe/

Keyo
  • 13,157
  • 17
  • 76
  • 107
  • 1
    I should add that the root cause of this was disk corruption on my virtual machine, which wasn't shutting down correctly. – Keyo Apr 26 '11 at 21:12

6 Answers6

11

Do you have clones of this repository elsewhere? You might want to read this post by Linus Torvalds to restore that corrupted object, assuming the corrupted object is a blob (file contents).

Andrew
  • 6,996
  • 3
  • 26
  • 38
Bram Schoenmakers
  • 1,561
  • 13
  • 19
  • No clones. I just set this up yesterday. So I only had 10 commits. I ended up starting fresh. But will definitely push it somewhere else at the end of every day. Lesson learned. Still glad to be off svn. Git is fast! – Keyo May 26 '10 at 00:36
  • 5
    Would be helpful to include the gist of the post in your answer, just incase, say, kernal.org ever gets hacked and is offline :( – SpoonMeiser Sep 12 '11 at 09:08
8

I wound up in the same situation, probably due to an improper shutdown of the virtual machine I was working in. There were approximately 10 objects in .git/objects that had zero length. As far as I can tell, the actual source code files were fine, just the repository was hosed.

$ git status
fatal: object fbcf234634ee04f8406cfd250ce5ab8012f92b08 is corrupted

Per some suggestions I saw elsewhere (including Linus's post referenced above), I tried temporarily moving the corrupted objects git was complaining about from .git/objects elsewhere. When had moved all of them, I got:

$ git status
fatal: bad object HEAD

After about an hour of Googling and trying various solutions, I gave up and started a new working copy using 'git clone' to pull from the origin (which was about 2 hours behind my working copy). I then used rsync -rC (-C excludes SCM files) to copy the changed files from the messed-up working copy to my new working copy.

Jase
  • 553
  • 5
  • 12
1

Simply delete the corrupt object that git is complaining about. I was able to resolve the same issue just now this way.

fatal: object 985a4870e7d890b314d2794377045a8b007c7925 is corrupted

For the above error, I was able to find corresponding object at:

project_directory/.git/objects/98/5a4870e7d890b314d2794377045a8b007c7925

Where you can see the file is 0 bytes and deleting it allowed the fetch to start working.

Presumably the previous fetch was interrupted, leaving the corrupt object with size = 0 bytes.

Anson Kao
  • 5,248
  • 4
  • 27
  • 36
1

Had the same problem, whichever git command I ran, It ended up with the message:

fatal: object <hash> is corrupted

I didn't have a backup and didn't want to lose my commits, so I decided to try Jase's solution and removed the 0 length file I had : .git/objects/00/<hash> Then got the same:

$ git status
fatal: bad object HEAD

Then, I tried to know what was wrong and looked into .git/refs/heads/masterwhere I had the hash.

I looked into .git/logs/refs/head/masterand found lines like this one:

<old commit> <new commit> <author> <timestamp> commit: <commit message>

I removed the last line (which had =) and pasted of this line into .git/refs/heads/master, erasing its content

I was then able to commit successfully.

isherwood
  • 52,576
  • 15
  • 105
  • 143
cube45
  • 2,771
  • 1
  • 19
  • 33
1

I had this same issue. I noticed that I wasn't logged in as root. When I logged in as root, I was able to check the log without the error sign.

To solidify this good status, I did this:

git add .
git commit -a -m "stabilize git"

I exited out of root and tried pulling from a client. It worked out for me afterwards.

When I did the add and commit, I knew that I was fine with what was in the directory. I had no changes visible through "git status".

1

You could also try to restore these objects by merely copying them from other repositories.

My virtual machine crashed while recording a pushed commit, so the objects were safely stored on a local computer. I scp'ed them to virtual machine and voila — git fsck outputs no errors.

Denis Gorbachev
  • 497
  • 4
  • 12