由于缺少对象,我可以如何处理 Git 损坏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4929674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:01:06  来源:igfitidea点击:

What can I do with Git corruption due to a missing object?

gitcorruption

提问by Cobby

I just went to clone a repository on another remote server and ran into an issue trying to do so:

我刚刚在另一台远程服务器上克隆了一个存储库,并在尝试这样做时遇到了一个问题:

git clone [email protected]:blah/blah/docs.git
Cloning into docs...
remote: Counting objects: 343, done.
remote: error: unable to find 14f87a739828e4d489b0310a51e057b30333926e
remote: Compressing objects: 100% (325/325), done.
error: git upload-pack: git-pack-objects died with error.   
fatal: git upload-pack: aborting due to possible repository corruption on the remote side.
remote: fatal: unable to read 14f87a739828e4d489b0310a51e057b30333926e
remote: aborting due to possible repository corruption on the remote side.
fatal: early EOF
fatal: index-pack failed

I did a little research and found out about git fsck, here is the output:

我做了一些研究,发现了关于git fsck,这是输出:

$ git fsck --full
error: sha1 mismatch 14f87a739828e4d489b0310a51e057b30333926e

error: 14f87a739828e4d489b0310a51e057b30333926e: object corrupt or missing
missing blob 14f87a739828e4d489b0310a51e057b30333926e

All other people with similar problems have a broken link issue or something. I'm still fairly new with Git, does anyone know how to fix this?

所有其他有类似问题的人都有链接断开问题或其他问题。我对 Git 还是很陌生,有谁知道如何解决这个问题?

I can still push to my central remote repository, but I can't clone it.

我仍然可以推送到我的中央远程存储库,但我无法克隆它。

14f87a739828e4d489b0310a51e057b30333926eis a blob that is a markdown file in the repository root. I tried deleting this file and push those changes to no avail.

14f87a739828e4d489b0310a51e057b30333926e是一个 blob,它是存储库根目录中的 Markdown 文件。我尝试删除此文件并推送这些更改无济于事。



Edit:Is it possible to import git history from a another repo? I'm thinking I could just start a new repo and copy my files into it and then import the commit history.

编辑:是否可以从另一个存储库导入 git 历史记录?我想我可以开始一个新的存储库并将我的文件复制到其中,然后导入提交历史记录。

回答by ssmir

Here is almost the same question with a very detailed solution: Github Repo Corruption - Sha1 Collision

这里有一个非常详细的解决方案几乎相同的问题:Github Repo Corruption - Sha1 Collision

回答by Koraktor

If it's only one single file and it's not packed yet, you should be able to find it in .git/objects/14/f87a739828e4d489b0310a51e057b30333926ein your local repository. You can copy this files to the corresponding directory in the repository on your server.

如果它只有一个文件并且尚未打包,您应该可以.git/objects/14/f87a739828e4d489b0310a51e057b30333926e在本地存储库中找到它。您可以将此文件复制到服务器上存储库中的相应目录。

If it is packed, you should be able to unpack it using git unpack-objectson one of the pack files in .git/objects/pack/. After that, copying to the server works as described above.

如果是包装,你应该能够使用解压它git unpack-objects在包文件之一.git/objects/pack/。之后,复制到服务器的工作如上所述。

回答by Jan Hudec

Simple push will not fix this problem, because git sees it has the commit that refers to the corrupt file and will assume it has all the objects it needs.

简单的推送不会解决这个问题,因为 git 看到它有引用损坏文件的提交,并且会假设它拥有它需要的所有对象。

Do you have another repository with the project that does not report any problems with fsck (and has the file in question)? E.g. on your local machine? Than you should try:

您是否有另一个项目存储库没有报告 fsck 的任何问题(并且有问题的文件)?例如在您的本地机器上?比你应该尝试:

  1. Put the corrupt repository aside.
  2. Clone the good repository in it's place.
  3. Push any branches the old repository had from other repositories or the old repository.
  1. 将损坏的存储库放在一边。
  2. 将好的存储库克隆到它的位置。
  3. 从其他存储库或旧存储库推送旧存储库的任何分支。

Since this kind of error means the file on disk was corrupt, I suggest you do a thorough check of the filesystem, the disk and also memory(the data could get corrupted in memory when git was saving them).

由于这种错误意味着磁盘上的文件已损坏,我建议您彻底检查文件系统、磁盘和内存(当 git 保存数据时,内存中的数据可能会损坏)。

Note: While all disks have at least some checksums, most memory chips have none at all, so a memory fault is more likely to go undetected than a disk fault. memtest86+is a good way to check memory.

注意:虽然所有磁盘都至少有一些校验和,但大多数内存芯片根本没有,因此内存故障比磁盘故障更有可能未被检测到。memtest86+是检查内存的好方法。