如何处理Git“无法读取"错误 [英] How to deal with Git "Could not read" error

查看:97
本文介绍了如何处理Git“无法读取"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在git存储库中收到此错误:

I am getting this error in my git repository:

22:09:15 $ git status
# On branch master
error: Could not read 8124cc15c63be92d534e4cdfa33c38d54deee122
error: unable to read tree object HEAD
nothing to commit (working directory clean)

Google搜索error: unable to read tree object HEAD并没有太大帮助,这种错误似乎非常少见.我不确定如何处理.可能是硬盘故障吗?

A Google search for error: unable to read tree object HEAD doesn't result in much help, this error seems to be very rare. I am not sure how to deal with it. Could it be a hard drive failure?

修改: git fsck的输出如下:

broken link from  commit 607328dc80e4901a55b95c683d4fbf43e6df28bf
              to    tree 8124cc15c63be92d534e4cdfa33c38d54deee122
missing tree 8124cc15c63be92d534e4cdfa33c38d54deee122
dangling tree 56b5d4a5e429d251582ec927bca7ef1225510c41
dangling tree 0259d2d38b18b6136bb6070fb41faf3624453cc6

推荐答案

在链接断开"消息上,您可以按照

On a "broken link" message, you could follow the GitFaq recommendations:

  • 备份您的所有状态,以便在您破坏更多内容时可以重做!
  • 爆炸所有损坏的包装文件
    • 请参阅"man git-unpack-objects",尤其是"-r"标志.
      另外,请意识到它只会解压缩尚不可用的对象,因此您需要先将打包文件从其正常位置移开(否则git-unpack-objects将找到打包中打包文件中的所有对象-file本身,根本不解压任何文件)
  • back up all your state so that anything you do is re-doable if you corrupt things more!
  • explode any corrupt pack-files
    • See "man git-unpack-objects", and in particular the "-r" flag.
      Also, please realize that it only unpacks objects that aren't already available, so you need to move the pack-file away from its normal location first (otherwise git-unpack-objects will find all objects that are in the pack-file in the pack-file itself, and not unpack anything at all)
  • 这是具有挑战性的部分.
    有时(希望如此!)您可以在存储库的其他副本中找到丢失的对象.
    在其他时候,您可能需要尝试以其他方式查找数据(例如,可能您签出的副本包含文件内容,这些内容在经过哈希处理后将成为丢失的对象?).
  • This is the challenging part.
    Sometimes (hopefully often!) you can find the missing objects in other copies of the repositories.
    At other times, you may need to try to find the data some other way (for example, maybe your checked-out copy contains the file content that when hashed will be the missing object?).


注意:


Notes:

  • missing objects can also be related to alternate (when you share objects between repositories) with git alternates (even though that can be risky).
  • The JGit/Egit eclipse plugin is also known to have a few issues.
    (Update February 2012: those plugins have come a long way and are now quite stable)

2016年7月(7年后)更新,Git 2.10即将发布,您现在拥有:

Update July 2016 (7 years laters), with Git 2.10 soon to be released, you now have:

git fsck --name-objects

它可以帮助命名这些断开链接的来源

It helps naming the origin of those broken links

有关更多信息,请参见"如何修复树到树之间的git错误断开链接?".

See "How to fix git error broken link from tree to tree?" for more.

这篇关于如何处理Git“无法读取"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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