Git拉取致命错误

3
当我尝试触发git pull命令时,它返回以下错误:

mert@eren-VirtualBox:~/restoranya/restoranya$ git pull origin master

error: object file .git/objects/2a/0836034919f0cfe0f8f1ab98037884dd1c93de为空

fatal: loose object 2a0836034919f0cfe0f8f1ab98037884dd1c93de(存储在.git/objects/2a/0836034919f0cfe0f8f1ab98037884dd1c93de中)已损坏

mert@eren-VirtualBox:~/restoranya/restoranya$ fatal:远程终端意外挂断

这种错误的原因是什么? 我应该怎么做才能恢复?
1个回答

2

出于某些原因,您的源远程对象已损坏。

您需要另一个克隆此存储库的副本,以便您可以运行

git cat-file -t 2a0836034919f0cfe0f8f1ab98037884dd1c93de

没有错误,您希望将该对象的良好版本注入到源对象数据库中。
描述修复操作可能有些棘手,因为我们正在谈论可能驻留在不同主机上并且可能由不同用户拥有的多个克隆。以下步骤假定您具有作为原始代码库所有者的用户对您的起源主机的shell访问权限。下面的提示“origin$”表示要在托管您的起源的计算机上运行的命令。
原点上的不良对象采用松散格式,因此恢复的最后一步是简单的复制。
假设良好克隆中的对象也是松散的,则运行:
origin$ cp /path/to/good-repo/.git/objects/\
2a/0836034919f0cfe0f8f1ab98037884dd1c93de \
/path/to/origin/objects/2a

如果您的起始点是一个裸仓库或者...
origin$ cp /path/to/good-repo/.git/objects/\
2a/0836034919f0cfe0f8f1ab98037884dd1c93de \
/path/to/origin/.git/objects/2a

否则。
如果在好的克隆中,此对象存储在一个包中,则需要将其取出。我建议在临时的、可丢弃的克隆中执行此操作。
origin$ git clone file:///path/to/good-repo /tmp/restore-repo

如果 good-repo 存储在另一台机器上,克隆的 URL 将会不同。
origin$ git clone user@other-machine:src/foo/.git /tmp/restore-repo

切换到包含您临时仓库的目录。

origin$ cd /tmp/restore-repo

将包文件移出对象数据库,因为如果git认为已经拥有这些对象,它就不会解压缩这些对象。

origin$ mkdir /tmp/restore-packs
origin$ mv .git/objects/pack/* /tmp/restore-packs

现在您已准备好解压缩。
origin$ for pack in /tmp/restore-packs/*.pack; do
  git unpack-objects -r < $pack
done

-r选项告诉git-unpack-objects继续解包,即使它遇到一个坏对象。

此时,/tmp/restore-repo应该包含2a08360…作为散装对象,因此运行

origin$ cp /tmp/restore-repo/.git/objects\
2a/0836034919f0cfe0f8f1ab98037884dd1c93de \
/path/to/origin/objects/2a

或者

origin$ cp /tmp/restore-repo/.git/objects\
2a/0836034919f0cfe0f8f1ab98037884dd1c93de \
/path/to/origin/.git/objects/2a

根据 origin 是否为裸仓库,做出相应的处理。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接