How to handle git gc fatal: bad object refs/remotes/origin/HEAD error?

后端 未结 8 1454
庸人自扰
庸人自扰 2021-01-30 02:36

I randomly hit this today while trying to run Git garbage collect:

$ git gc
fatal: bad object refs/remotes/origin/HEAD
error: failed to run repack
         


        
8条回答
  •  终归单人心
    2021-01-30 03:28

    The problem that I ran into (which is the same problem that @Stavarengo mentioned in this comment above) is that the default remote branch (develop in my case) had been deleted, but was still referenced in .git/refs/remotes/origin/HEAD.

    Opening .git/refs/remotes/origin/HEAD in my editor showed this:

    ref: refs/remotes/origin/develop
    

    I carefully edited it to point at my new default branch and all was well:

    ref: refs/remotes/origin/master
    

    The clue that tipped me off was that running git prune showed this error:

    > git prune
    warning: symbolic ref is dangling: refs/remotes/origin/HEAD
    

提交回复
热议问题