【问题标题】:restoring git repository from bundle backup从包备份恢复 git 存储库
【发布时间】:2012-04-06 03:13:00
【问题描述】:

我创建了我的 git 存储库的备份,例如 How to backup a local Git repository? 建议 与

git bundle create /tmp/foo-all --all

我可以看到所有的 ref 都在里面,包括一个由 git-svn 创建的远程 ref。 现在我不知道如何再次将此捆绑包恢复到本地存储库。 我很确定我已经做过一次了。我尝试了 git-clone ,但这给了我一个存储库,其中包含我的备份包作为远程存储库。

我也试过

git init
git bundle unbundle /tmp/foo --all 

但这只是列出了所有引用...

验证捆绑包给出:

$ git bundle verify $somewhere/foo.bundle 
The bundle contains 12 refs
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/master
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/remotes/git-svn
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx HEAD
The bundle requires these 0 ref
$somewhere/foo.bundle is okay

【问题讨论】:

    标签: git backup restore


    【解决方案1】:

    简答:

    $ git bundle verify $somewhere/foo.bundle
    $ git clone $somewhere/foo.bundle
    Cloning into 'foo'...
    Receiving objects: 100% (10133/10133), 82.03 MiB | 74.25 MiB/s, done.
    Resolving deltas: 100% (5436/5436), done.
    $ cd foo
    $ git status
    ...
    

    懒獾这么说,但在最后一段。 :)

    【讨论】:

      【解决方案2】:

      我更新版本的 git 就够了:

      git clone bundle.file
      

      整个命令:

      mkdir ~/git
      cd ~/git
      git clone /path/to/bundle.file
      

      它将完全恢复您的 git 裸存储库内容(将作为正常源进行编译)。 您不需要任何其他文件。 bundle文件就够了。

      在解包之前始终验证您的捆绑文件是明智的,如下所示:

      git bundle verify /path/to/bundle.file 
      

      【讨论】:

        【解决方案3】:

        Bundle 不包含文件,但 deltas,您需要 基础 才能重新创建文件内容。 您必须先克隆,然后再解绑。仅在 bundle 需要 0 refs 的情况下才允许使用 init 而不是 clone

        解绑前不要忽略git bundle verify

        git-bundle(1) - Linux man page

        用于检查捆绑文件是否有效,并且将干净地应用于 当前存储库。这包括对捆绑格式的检查 本身以及检查先决条件提交是否存在并且是 在当前存储库中完全链接。 git bundle 打印一个列表 缺少提交(如果有),并以非零状态退出。

        如果您正在创建存储库,那么您可以从包中克隆,就像它是远程存储库一样,而不是创建一个空的存储库,然后从包中拉取或获取对象

        【讨论】:

        • @user1283719 git clone foo.bundle?
        • git clone foo.bundle 使用我的备份包作为远程存储库创建一个新存储库,如上所述。我的本地存储库无法修复,所以我想从备份中恢复它,包括在其远程分支上使用 git-svn 的能力。
        • @user1283719 - 只需在配置中编辑 [remote "origin"]... 或使用 git pull foo.bundle 而不是克隆
        • @user1283719 IIRC 捆绑时 svn 信息丢失。所以你可能需要用 svn 元信息备份整个 repo
        【解决方案4】:
        git bundle unbundle /tmp/foo --all 
        

        但这只是列出了所有引用...

        实际上,它现在可以做的不止这些:

        Git 2.34(2021 年第四季度)将进度显示添加到“git bundle unbundle(man)

        除了this answer中提到的git bundle verify之外,它至少会告诉你发生了什么。

        参见Ævar Arnfjörð Bjarmason (avar)@commit d941cc4commit f46c46ecommit 7366096(2021 年 9 月 5 日)和commit 0834257(2021 年 8 月 26 日)。
        (由@987654330 中的Junio C Hamano -- gitster -- 合并@,2021 年 9 月 20 日)

        bundle: 显示“解绑”进度

        签字人:Ævar Arnfjörð Bjarmason

        2e0afaf("Add git-bundle: move objects and references by archive", 2007-02-22, Git v1.5.1-rc1 -- merge) 中添加的“unbundle”命令没有显示进度输出,即使底层 API 学会了如何在 be042af 中显示进度(“Teach progress eye-candy to fetch_refs_from_bundle()”,2011-09-18,Git v1.7.8-rc0 -- merge)。

        现在我们将使用新的--progress-title 选项 togit index-pack"(man) 显示“取消捆绑对象”,以配合现有的“接收对象”和“索引对象” "(分别在使用“--stdin”和打包文件调用时显示)。

        与“git bundle create”不同(man)我们在这里不处理“--quiet”,也不处理“--all-progress”和“--all-progress-implied”。
        这些都是特定于“创建”(和“验证”,在“--quiet”的情况下)。

        现有文档的结构有点不清楚,例如仅在 79862b6 中添加的“--quiet”选项的文档(“bundle-create:进度输出控制”,2019-11-10,Git v2.25.0-rc0 -- merge 仅在 batch #2 中列出)描述了它如何用于“create”,而不是“verify”。
        应该解决其中的那个问题和其他问题,但我想避免现在解决这个烂摊子。
        让我们在这里隐式支持标准的“--no-progress”,并留下清理“git bundle(man) 的一般行为以供以后更改。

        git bundle 现在包含在其man page 中:

        'git bundle' unbundle [--progress] <file> [<refname>...]
        

        【讨论】:

          【解决方案5】:

          我尝试了 git-clone,但这给了我一个存储库,其中包含我的备份包作为远程存储库。

          Bundle 不存储原始存储库 URL。您必须手动指定它:

          git clone foo.bundle
          cd foo
          git remote set-url origin url-to-original-repository
          

          现在您可以从原始存储库中获取并推送到原始存储库。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-05-11
            • 1970-01-01
            相关资源
            最近更新 更多