如何处理损坏的 Git 对象文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4111728/
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 do I deal with corrupted Git object files?
提问by Mike
I did a Git pull when I was near my quota, and as a result (so I think), got a corrupted file:
当我接近我的配额时,我做了一个 Git 拉取,结果(我认为),得到了一个损坏的文件:
$ git pull
walk dffbfa18916a9db95ef8fafc6d7d769c29a445aa
fatal: object d4a0e7599494bfee2b5351113895b43c351496b3 is corrupted
$ git fsck --full
bad sha1 file: .git/objects/66/b55c76947b1d38983e0944f1e6388c86f07a1b.temp
fatal: object d4a0e7599494bfee2b5351113895b43c351496b3 is corrupted
$ git cat-file -t d4a0e7599494bfee2b5351113895b43c351496b3
error: unable to find d4a0e7599494bfee2b5351113895b43c351496b3
fatal: git cat-file d4a0e7599494bfee2b5351113895b43c351496b3: bad file
How can I solve this corruption?
我该如何解决这种腐败问题?
.git/objects/66/b55c76947b1d38983e0944f1e6388c86f07a1b.temp was zero bytes; deleting it did nothing to solve my problem (same errors).
.git/objects/66/b55c76947b1d38983e0944f1e6388c86f07a1b.temp 为零字节;删除它并没有解决我的问题(同样的错误)。
采纳答案by Cascabel
In general, fixing corrupt objects can be pretty difficult. However, in this case, we're confident that the problem is an aborted transfer, meaning that the object is in a remote repository, so we should be able to safely remove our copy and let git get it from the remote, correctly this time.
一般来说,修复损坏的对象可能非常困难。但是,在这种情况下,我们确信问题是传输中止,这意味着该对象位于远程存储库中,因此我们应该能够安全地删除我们的副本并让 git 从远程获取它,这一次是正确的.
The temporary object file, with zero size, can obviously just be removed. It's not going to do us any good. The corrupt object which refers to it, d4a0e75...
, is our real problem. It can be found in .git/objects/d4/a0e75...
. As I said above, it's going to be safe to remove, but just in case, back it up first.
零大小的临时目标文件显然可以被删除。这对我们没有任何好处。引用它的损坏对象d4a0e75...
是我们真正的问题。它可以在.git/objects/d4/a0e75...
. 正如我上面所说,删除它是安全的,但为了以防万一,请先备份它。
At this point, a fresh git pull
should succeed.
在这一点上,一个新鲜git pull
应该成功。
...assuming it was going to succeed in the first place. In this case, it appears that some local modifications prevented the attempted merge, so a stash
, pull
, stash pop
was in order. This could happen with any merge, though, and didn't have anything to do with the corrupted object. (Unless there was some index cleanup necessary, and the stash did that in the process... but I don't believe so.)
...假设它首先会成功。在这种情况下,似乎一些本地修改阻止了尝试的合并,因此 a stash
, pull
,stash pop
是有序的。但是,任何合并都可能发生这种情况,并且与损坏的对象没有任何关系。(除非需要进行一些索引清理,并且存储在此过程中会这样做……但我不这么认为。)
回答by eid
You can use "find" for remove all files in the /objects
directory with 0 in size with the command:
您可以使用“查找”通过以下命令删除/objects
目录中大小为 0 的所有文件:
find .git/objects/ -size 0 -delete
Backup is recommended.
建议备份。
回答by Frosty
Recovering from Repository Corruptionis the official answer.
从存储库损坏中恢复是官方的答案。
The really short answer is: find uncorrupted objects and copy them.
真正简短的答案是:找到未损坏的对象并复制它们。