git-annex/ tips/ recovering from a corrupt git repository

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 (!).

1. Create a clone of a known good repository.
2. Add the clone as an object alternate to the broken repository.
3. Do a `git-repack -a -d` to lift the external objects into repo-local packs.
4. Remove the clone

[[!format sh """ $ 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. ;-)

comment 8
Several machines started showing this behavior around 4.20131106 or 4.20131101. I will find a way to reproduce when I can find the time.
Comment by http://id.clacke.se/ — Tue Jul 22 18:11:47 2025
comment 7

> I tried 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

`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.

Comment by http://joeyh.name/ — Tue Jul 22 18:11:47 2025
comment 6
This is my symptom too: Git annex 'corrupting' itself
Comment by http://id.clacke.se/ — Tue Jul 22 18:11:47 2025
comment 6
If you can reliably corrupt a git repository, it's highly likely your hardware (disk or memory) is broken.
Comment by http://joeyh.name/ — Tue Jul 22 18:11:47 2025
comment 4
Hm. This is bad. My hunch that btrfs was the culprit seems to have been wrong. After having switched things around, along with lots of `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.
Comment by http://id.clacke.se/ — Tue Jul 22 18:11:47 2025
comment 3
Luckily, so far the objects getting corrupted have been in past commits (maybe only in packfiles?), not the latest ones, so I have been able to recover even though HEAD has been unique to the local repo.
Comment by http://id.clacke.se/ — Tue Jul 22 18:11:47 2025
comment 2
I am using git-annex 20131106 and I tried `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.
Comment by http://id.clacke.se/ — Tue Jul 22 18:11:47 2025
comment 1
Better, since version 4.20131024, `git annex repair` can be run to automatically do this, and more. (Including recovering data in corrupt git repositories that you forgot to push!)
Comment by http://joeyh.name/ — Tue Jul 22 18:11:47 2025
Comments on this page are closed.