Git损坏的存储库:如何从干净的存储库中选择git对象 [英] Git corrupted repo: how to pick a git object from a clean repository

查看:94
本文介绍了Git损坏的存储库:如何从干净的存储库中选择git对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有关已损坏的Git存储库(正是一个出错的松散对象)的众多问题之一:

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.
error: inflate: data stream error (unknown compression method)
error: unable to unpack 831a5d31af4a0af2f5a367689bee27a44efc22c9 header
Delta compression using up to 6 threads.
Compressing objects: 100% (3283/3283), done.
error: inflate: data stream error (unknown compression method)
fatal: loose object 831a5d31af4a0af2f5a367689bee27a44efc22c9 (stored in .git/objects/83/1a5d31af4a0af2f5a367689bee27a44efc22c9) is corrupt
error: failed to run repack

按照有关该主题的现有答案进行操作(如何处理损坏的git对象文件?由于Git损坏,我该怎么办?到丢失的对象?)我已经从损坏的存储库中删除了对象831a5d31.

Following existing answers on the subject (How do I deal with corrupted git object files?, How to fix corrupted git repository?, or What can I do with Git corruption due to a missing object?) I already removed the object 831a5d31 from the corrupted repository.

在我的情况下,我有一个存储库的克隆,该克隆似乎包含我所缺少的对象,但是在objects/83/1a5d31af4a0af2f5a367689bee27a44efc22c9处没有文件.我该如何修复我的存储库?

In my case I have a clone of the repository, that seems to hold the object I'm missing, but there's no file at objects/83/1a5d31af4a0af2f5a367689bee27a44efc22c9. How can I do to fix my repository?

推荐答案

文件是否在其他位置

干净存储库的对象已重新打包,这就是为什么它不再作为文件存在的原因.

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

要还原它,请先使用

git show 831a5d31af4a0af2f5a367689bee27a44efc22c9 > 831a5-file

831a5-file移至损坏的存储库中,然后运行

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

git hash-object -w 831a5-file

确保输出中给出的SHA1为831a5d31af4a0af2f5a367689bee27a44efc22c9

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

这将存储对象,并且存储库已修复!

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

如果文件在其他位置不存在

如果文件在其他地方不存在,即损坏发生在提交后但在您能够推送之前,则可以通过一种方法来还原您的存储库并重新提交更改.请参阅有关相关问题的答案.

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.

这篇关于Git损坏的存储库:如何从干净的存储库中选择git对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆