Monday, December 28, 2009

Corrupted Git

Well, I have a directory with all my undergraduate project and I use git to ease my work, but recently I was not able to create a backup in a external disk because a error:


remote: Counting objects: 313, done.
remote: Compressing objects: 100% (116/116), done.
fatal: pack has bad object at offset 11893474: inflate returned 1
fatal: index-pack failed


I have files of almost 500MB on this repo, I suppose that the problem. I try to repack but it was useless, I also can check the hash of the object (with fsck), but I can't find where is that file, or what commit it belongs to.

This code will help in this case:


git checkout master
git branch new_master
git checkout new_master
for i in $!$(seq 1 100); do git checkout new_master~$!$i || break; done
for j in $!$(seq $!$i 100); do git checkout new_master~$!$j && break; done
# The error is between new_master~$!$j and new_master~($!$i-2)
git checkout master
git branch -D new_master
git branch new_master
git checkout new_master
git rebase --onto new_master~$!$j new_master~$!$((i-2)) new_master


It works (al least for my problem!!!), and now i want to rebase master:

git checkout master
git rebase new_master
git branch -d new_master


That's all.

No comments: