如何处理被损坏的git对象文件?

时间:2021-08-09 22:48:33

I did a git pull when I was near my quota, and as a result (so I think), got a corrupted file:

当我接近我的配额时,我做了一个git pull,结果(所以我认为)得到了一个损坏的文件:

$ 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).

. / / 66 / b55c76947b1d38983e0944f1e6388c86f07a1b对象。温度是零字节;删除它没有解决我的问题(同样的错误)。

3 个解决方案

#1


31  

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…这是我们真正的问题。它可以发现在. /对象/ 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.)

…假设它一开始就会成功。在这种情况下,似乎一些局部修改阻止了尝试合并,因此,一个隐藏的、拉的、隐藏的pop是有序的。但是,这可能发生在任何合并中,并且与被损坏的对象没有任何关系。(除非有一些必要的索引清理,而这些隐藏在过程中……)但我不这么认为。

#2


15  

you can use "find" to remove all files in /objects folder with 0 size with command find .git/objects/ -size 0 -delete. Backup is recommended.

您可以使用“find”来删除/objects文件夹中的所有文件,其中有0个大小的命令找到。git/对象/ -size 0 -delete。建议备份。

#3


5  

Recovering from Repository Corruption is the official answer.

官方的回答是,从仓库的腐败中恢复过来。

the really short answer is: find uncorrupted objects and copy them.

真正简短的答案是:找到未被损坏的对象并复制它们。

#1


31  

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…这是我们真正的问题。它可以发现在. /对象/ 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.)

…假设它一开始就会成功。在这种情况下,似乎一些局部修改阻止了尝试合并,因此,一个隐藏的、拉的、隐藏的pop是有序的。但是,这可能发生在任何合并中,并且与被损坏的对象没有任何关系。(除非有一些必要的索引清理,而这些隐藏在过程中……)但我不这么认为。

#2


15  

you can use "find" to remove all files in /objects folder with 0 size with command find .git/objects/ -size 0 -delete. Backup is recommended.

您可以使用“find”来删除/objects文件夹中的所有文件,其中有0个大小的命令找到。git/对象/ -size 0 -delete。建议备份。

#3


5  

Recovering from Repository Corruption is the official answer.

官方的回答是,从仓库的腐败中恢复过来。

the really short answer is: find uncorrupted objects and copy them.

真正简短的答案是:找到未被损坏的对象并复制它们。