How do I deal with corrupted Git object files?

后端 未结 4 1428
不知归路
不知归路 2020-12-05 01:29

I did a Git pull when I was near my quota, and as a result (so I think), got a corrupted file:

$ git pull
walk dffbfa18916a9db95ef8fafc6d7d769c29a445aa
fata         


        
相关标签:
4条回答
  • 2020-12-05 01:56

    For anyone stumbling across the same issue:

    I fixed the problem by cloning the repo again at another location. I then copied my whole src dir (without .git dir obviously) from the corrupted repo into the freshly cloned repo. Thus I had all the recent changes and a clean and working repository.

    0 讨论(0)
  • 2020-12-05 02:01

    Recovering from Repository Corruption is the official answer.

    The really short answer is: find uncorrupted objects and copy them.

    0 讨论(0)
  • 2020-12-05 02:05

    In general, fixing corrupt objects can be pretty difficult. However, in this case, we're confident that the problem is an aborted transfer, meaning that the object is in a remote repository, so we should be able to safely remove our copy and let git get it from the remote, correctly this time.

    The temporary object file, with zero size, can obviously just be removed. It's not going to do us any good. The corrupt object which refers to it, d4a0e75..., is our real problem. It can be found in .git/objects/d4/a0e75.... As I said above, it's going to be safe to remove, but just in case, back it up first.

    At this point, a fresh git pull should succeed.

    ...assuming it was going to succeed in the first place. In this case, it appears that some local modifications prevented the attempted merge, so a stash, pull, stash pop was in order. This could happen with any merge, though, and didn't have anything to do with the corrupted object. (Unless there was some index cleanup necessary, and the stash did that in the process... but I don't believe so.)

    0 讨论(0)
  • 2020-12-05 02:19

    You can use "find" for remove all files in the /objects directory with 0 in size with the command:

    find .git/objects/ -size 0 -delete
    

    Backup is recommended.

    0 讨论(0)
提交回复
热议问题