making things better, making better things

Monday, May 11, 2009

I uncorrupted a git database!

… but it was touch and go there for a while.

RubyMine is out, and I’d felt positive enough about the beta that I wanted to give it a try… but I didn’t want to do it in any existing working directory, in case it did stupid stuff with my files. So, simple enough, just clone the git repository:

[556] RubymineProjects $ git clone ~/Documents/workspace/tourette
Initialized empty Git repository in /Users/eostrom/RubymineProjects/tourette/.git/
fatal: object 3a37e547408f1f955337bade61807ef021608760 is corrupted

Fatal?!? I don’t like the sound of that.

The object in question was an empty file. There isn’t a lot of advice on Google about how to deal with fatal git corruption; and what there is mostly says “maybe you can recover that object from an upstream repository”. Well, this was the only repository. And even though I’d kept backups since the point of corruption (thanks, Time Machine!), it turned out this file had always been empty. What now?

I’ll tell you what didn’t work: Most stuff. Some people tell you to use git fsck to figure out what’s wrong; well, it didn’t work because of fatal corruption. I tracked the problem down to a specific commit (updating a plugin), and learned how you can use git rebase to make it as if that commit was never born; guess what, fatal corruption. Yeah, git’s been working fine for three weeks with this corrupt object (and others) lurking in the repository; but once you discover the rot within and start poking at it with git’s surgical tools, well: You can’t fix the repository, because the repository’s broken.

Eventually I discovered four corrupt objects. Three of them I could recover from old backups (thanks again, Time Machine!). The other one had never not been corrupt, as far as I could tell. The trick was in the git FAQ – it just took me a long time to figure out to look for it there. (The winning search was ‘git repair “broken link”‘, that last phrase coming from git fsck once I had a partial fix.)

… And I just did what it says in the FAQ: git fsck to identify the broken object, and what links to it; git ls-tree to find out what file it was supposed to represent; and, well, it was supposed to be the latest version of a file from the plugin, so git hash-object and I was done!

Now, back to trying out RubyMine. Or, wait – first, a drink.

posted by erik at 5:45 pm  

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress