Git corrupted repo: how to pick a git object from a clean repository

前端 未结 1 1511
遇见更好的自我
遇见更好的自我 2021-01-18 00:54

This is one of the numerous questions regarding a Git repo that is corrupted, precisely a loose object that went wrong:

$ git gc
Counting objects: 3299, done         


        
相关标签:
1条回答
  • 2021-01-18 01:20

    If the file exists elsewhere

    The object of the clean repository has been repacked, that's why it doesn't exist anymore as a file.

    To restore it, first save it as a file, from the clean repository, with

    git show 831a5d31af4a0af2f5a367689bee27a44efc22c9 > 831a5-file
    

    Move 831a5-file in the corrupted repo, and run

    git hash-object -w 831a5-file
    

    Make sure that the SHA1 given in the output is 831a5d31af4a0af2f5a367689bee27a44efc22c9

    This will store the object, and the repository is fixed!

    If the file does not exist elsewhere

    If the file doesn't exist elsewhere, i.e. the corruption occurred after commit but before you were able to push, there is a way to restore your repo and and re-commit the changes. See this answer to a related question.

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