git拉致命错误

时间:2012-06-14 09:24:07

标签: git virtualbox git-pull ubuntu-12.04

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

  

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

     

错误:目标文件   .git / objects / 2a / 0836034919f0cfe0f8f1ab98037884dd1c93de为空

     

致命:松散物体2a0836034919f0cfe0f8f1ab98037884dd1c93de(存放)   在   .git / objects / 2a / 0836034919f0cfe0f8f1ab98037884dd1c93de)已损坏

     

mert @ eren-VirtualBox:〜/ restoranya / restoranya $ fatal:远程端   意外地挂了

出现这种错误的原因是什么?我该怎么做才能恢复?

2 个答案:

答案 0 :(得分:2)

由于某种原因,该对象在您的原始遥控器中已损坏。

您需要另一个此存储库的克隆,您可以在其中运行

git cat-file -t 2a0836034919f0cfe0f8f1ab98037884dd1c93de

没有错误,并且您希望将该对象的良好版本注入到origin的对象数据库中。

描述修复可能很棘手,因为我们讨论的是可能驻留在不同主机上并且可能由不同用户拥有的多个克隆。以下步骤假定您拥有对作为拥有源存储库的用户的源主机的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在另一台计算机上,则克隆网址将不同。

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是否是裸存储库。

答案 1 :(得分:0)

你尝试重新包装吗?

git-repack is used to combine all objects that do not currently reside in a "pack",
into a pack. It can also be used to re-organize existing packs into a single, more
efficient pack.
A pack is a collection of objects, individually compressed, with delta compression 
applied, stored in a single file, with an associated index file. Packs are used 
to reduce the load on mirror systems, backup engines, disk storage, etc.

有一些清洁你的回购的命令..

$ git-prune
$ git-gc --aggressive
$ git-repack
$ git-repack -a
$ git-prune-packed
相关问题