Backups. What a better time to test ’em than when you need ’em. Don’t lie. I know you’ve been there too. In an unfortunate turn of events, I had to restore a number of bare git repos from recent off-site copies (made with the handy rdiff-backup), but they needed a bit more work to be functional.
Once restored, I couldn’t pull
or push
from my existing working copies. I was greeted with cryptic error messages instead: fatal: git upload-pack: not our ref 0000000000000000000000000000000000000000
and ! [remote rejected] master -> master (missing necessary objects)
, respectively.
No amount of searching led to an adequate solution. So I simply leveraged git’s distributedness, and used one of the clone to recreate my bare repo. I was nonetheless a bit worried about having lost a few commits on the tip.
Playing in the bare repo later on led me to a more satisfying solution. Apparently, the refs/heads/master
file was corrupted (empty), and editing it to contain the full sha-1
of the tip was enough to fix the issue. I found the sha-1
of the desired commit in the packed-refs
file at the root of the bare repo. Once done, everything worked as before, and pre-existing working copies were able to pull
and push
without issue.
I learned two things:
- A bit more about git
- That I didn’t actually have any more commits there
Backups! Yay!
Continue reading