How can I repair a git repository with a missing object?

前端 未结 3 751
暗喜
暗喜 2021-02-19 16:59

My development repository at some point lost an object.

$ git fsck
fatal: failed to read object 2ffffdc84156fa30e4614a7ea5a1895885011b8db8: Invalid argument
$ git          


        
3条回答
  •  太阳男子
    2021-02-19 17:35

    I recently had a bunch of missing objects in a local repository and an uncorrupted reference repository to restore it from. Here's the magic I came up with that worked for me:

    cd 
    git unpack-objects < /objects/pack/pack-.pack
    

    It turns out that all of the objects I needed were in a pack file in the reference repository instead of in separate "loose" object files. This simple incantation unpacks that pack file into the local database, filling in the holes. After doing

    git gc
    

    to cleanup any dangling commits (i.e. due to rebasing, amend commits, etc.) my git fsck is now clean.

提交回复
热议问题