【问题标题】:git pull fatal errorgit pull 致命错误
【发布时间】:2012-06-17 07:32:11
【问题描述】:

当我尝试触发 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: 远端 意外挂断了

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

【问题讨论】:

    标签: git virtualbox git-pull ubuntu-12.04


    【解决方案1】:

    你试过重新包装吗?

    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
    

    【讨论】:

      【解决方案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 是否是一个裸仓库。

      【讨论】:

        猜你喜欢
        • 2016-03-11
        • 2019-02-02
        • 2012-03-18
        • 2023-03-08
        • 2015-01-25
        • 1970-01-01
        • 2017-05-26
        • 2019-07-07
        • 1970-01-01
        相关资源
        最近更新 更多