如何诊断和修复 git 致命:无法读取树
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20870895/
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
How to diagnose and fix git fatal: unable to read tree
提问by cmhughes
I'm using git
to manage files on a project, and keep running into this problem.
我git
用来管理项目上的文件,并不断遇到这个问题。
When I run git status
I get the message
当我跑步时,git status
我收到消息
fatal: unable to read tree e2d920161d41631066945a3cbcd1b043de919570
As I understand it, I should check the output of git fsck
, and I receive
据我了解,我应该检查 的输出git fsck
,然后我收到
broken link from tree e09a42f248afff64336fbbec2523df97c26451ac
to tree e2d920161d41631066945a3cbcd1b043de919570
broken link from tree e09a42f248afff64336fbbec2523df97c26451ac
to tree 9b0dd389bd7f9e8d257395d57e0881b7957f9698
broken link from tree e09a42f248afff64336fbbec2523df97c26451ac
to tree 9e288a4ad60d63f342dfd18237980674426aa725
broken link from tree e09a42f248afff64336fbbec2523df97c26451ac
to tree 2a04647337089f554fab8c49cfd37149e5f4fc9f
broken link from tree e09a42f248afff64336fbbec2523df97c26451ac
to tree ea16658b45ce961adc3c3f519b0e8d9672918ca8
together with a lot of missing blob
messages.
连同大量的missing blob
消息。
Following various resources (e.g Git - Broken Links, Missing & Dangling Trees) I have simply re-cloned the project from github
and started again.
根据各种资源(例如Git - Broken Links、Missing & Dangling Trees),我简单地重新克隆了该项目github
并重新开始。
Once I have re-cloned the project, all is good for a few commit
s, and then the problem arises again. Re-cloning every time doesn't seem to be optimal, and seems to go against the idea of using git
, and I'd like to try and understand what is going on. How can I diagnose and fix this problem?
一旦我重新克隆了该项目,几commit
秒钟就一切正常,然后问题再次出现。每次重新克隆似乎都不是最佳选择,似乎与使用 的想法背道而驰git
,我想尝试了解发生了什么。如何诊断和解决此问题?
采纳答案by VonC
Following my older recommendation, it boils down to being able to find a repo which actually contains the missing elements (here full trees).
This is what is shown in "How to fix corrupted git repository?".
按照我较早的建议,归结为能够找到一个实际上包含缺失元素的存储库(这里是完整的树)。
这就是“如何修复损坏的 git 存储库?”中显示的内容。
But if a full clone doesn't solve the problem, then it may be:
但是如果一个完整的克隆没有解决问题,那么它可能是:
- a corruption of the repo on the GitHub side (contact GitHub support to check).
- some kind of corruption on the client side (your Ubuntu). Make sure to check if the issue persists with the latest Git release(1.8.5.2-1) from a custom PPA (Personal Package Archive).
- GitHub 端的 repo 损坏(联系 GitHub 支持检查)。
- 客户端(您的 Ubuntu)上的某种损坏。确保使用自定义 PPA(个人包存档)中的最新 Git 版本(1.8.5.2-1)检查问题是否仍然存在。
Update July 2016, with Git 2.10 soon to be release, you now have:
2016 年 7 月更新,随着 Git 2.10 即将发布,您现在拥有:
git fsck --name-objects
See "How to fix git error broken link from tree to tree?" for more.
有关更多信息,请参阅“如何修复从树到树的 git 错误断开的链接?”。
回答by Mark Leighton Fisher
I would start with a fresh clone, then run git fsck
on the unchanged, untouched clone. I'm wondering (as above) if your initial clone is corrupt, but in a way allowing you to perform a few operations before orphaning the trees.
我会从一个新的克隆开始,然后git fsck
在未更改的、未受影响的克隆上运行。我想知道(如上所述)您的初始克隆是否已损坏,但在某种程度上允许您在孤立树之前执行一些操作。
回答by Duncan Babbage
This may or may not be the problem originally raised here, but note that you will see a "fatal: unable to read tree" error from git if the user account the git command is being run under is no longer able to read all files checked out from your repository due to an ownership/permissions issue.
这可能是也可能不是这里最初提出的问题,但请注意,如果运行 git 命令的用户帐户不再能够读取所有检查过的文件,您将看到来自 git 的“致命:无法读取树”错误由于所有权/权限问题,从您的存储库中删除。
So in many case the first thing to check should be that you've got ownership and permissions set correctly on the files in your working tree, as that may well fix the problem. :)
因此,在许多情况下,首先要检查的应该是您在工作树中的文件上正确设置了所有权和权限,因为这很可能会解决问题。:)
回答by risingfish
Something that just worked for me was stashing my changes, doing a git pull, and then popping the changes back off the stash stack. My corruption might of been pretty shallow, so it probably won't work for everyone but it's worth a try.
对我有用的东西是隐藏我的更改,执行 git pull,然后将更改从存储堆栈中弹出。我的腐败可能很肤浅,所以它可能不会对每个人都有效,但值得一试。
Here's the output I got when I stashed:
这是我藏匿时得到的输出:
work@home ~/code/project $ git stash
fatal: unable to read tree 5fd5f4d0425b42e5b478773fa643dd6fd4918188
fatal: unable to read tree 5fd5f4d0425b42e5b478773fa643dd6fd4918188
Saved working directory and index state WIP on master: d93430c Generic commit msg.
HEAD is now at d93430c An older generic message.
After that I pulled and then popped and it cleaned itself up. Again, YMMV.
在那之后,我拉了然后弹出,它自己清理了。再次,YMMV。