I have found this the most reliable way to recover from a corrupt git repository. I have had a lot of them lately, there might be a regression in btrfs in Ubuntu's Linux 3.8.0-33 (!).
- Create a clone of a known good repository.
- Add the clone as an object alternate to the broken repository.
- Do a
git-repack -a -d
to lift the external objects into repo-local packs. - Remove the clone
$ cd /tmp/
$ git clone good-host:/path/to/good-repo
$ cd /home/user/broken-repo
$ echo /tmp/good-repo/.git/objects/ > .git/objects/info/alternates
$ git repack -a -d
$ rm -rf /tmp/good-repo
... and push early, push often.
git annex repair
can be run to automatically do this, and more. (Including recovering data in corrupt git repositories that you forgot to push!)git annex repair
first. It seems git is making assumptions that if I have object A then I must have object B that A depends on. Or maybe it freaks out because the object is not missing, just full of zeroes. I haven't done any analysis on exactly what situation causes this. When I have time, I will.git annex sync
in various places, I now have a corrupt repo on ext4. It must be git or git-annex that does something wrong.git annex repair
is supposed to deal with these situations. If it fails to fix such a broken repository, please file a detailed bug report, ideally with a link to a copy of the repository.