I have a git repository that has several worktree directories. Sometime in the past couple of months, something has gone wrong, possibly because my computer got hung a couple of times and I had to hard restart. : (
Anyway, whenever I now try to run git gc
(or, more usually, gc
is run in the background when I fetch
), I get the following error output:
warning: reflog of 'HEAD' references pruned commits
warning: reflog of 'HEAD' references pruned commits
warning: reflog of 'HEAD' references pruned commits
warning: reflog of 'HEAD' references pruned commits
warning: reflog of 'HEAD' references pruned commits
warning: reflog of 'HEAD' references pruned commits
warning: reflog of 'HEAD' references pruned commits
warning: reflog of 'HEAD' references pruned commits
warning: reflog of 'HEAD' references pruned commits
warning: reflog of 'HEAD' references pruned commits
Counting objects: 1255885, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (220739/220739), done.
fatal: unable to read 12e33ebd327a094eaaf844722760cd303fe5bcc5
error: failed to run repack
I've checked and no object with that SHA exists in my .git
directory. (Yes, I know to look in .git/objects/12
)
I've tried to find where that SHA might be being referenced a couple of ways. First I did a recursive grep on my .git
directory for both the full SHA and (just in case) all but its first 2 digits. Found nothing except log entries (in various worktree directories), reporting the same "fatal" error as above.
After doing a bunch of reading (of both various SO answers and articles on the web, particularly this one, I also grep
'd the output of git verify-pack -v
for the problematic SHA and found nothing there either.
I assume, from the multiple warning
lines, that somewhere I have a reflog or something that is referring to that ID, but I am unable to find such a reference anywhere.
Complication: I know that one of the standard 'remedies' is simply "Re-clone the repo from the origin and start over". I'd rather not do that for a couple of reasons: I really don't want to have to rebuild all my worktrees, and; I have a few commits and branches that I can't push )(because they don't belong in the remote repo) but that are useful to me, and I would not like to lose them.
So, if at all possible, I'd like to find a way to repair this problem. Also, it would be personally satisfying (and I'd learn a lot about Git in the process — I already have!) to be able to fix it.
Any ideas?