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

家住魔仙堡 提交于 2019-12-01 17:42:05
CharlesB

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!