如何git捆绑完整的回购


116

我需要将完整的存储库转移到新的非联网计算机,最好是作为单个文件实体。git的捆绑允许git fetchgit pull操作风格在sneakernet环境,但似乎假设你已经在目标计算机上回购的工作版本。

什么是正确的调用:

  1. 捆绑当前仓库中的所有分支
  2. 在目标目录上启动新存储库,即正确安装根提交

我已经向上游发送了一个补丁以进行澄清:

`git clone` can use any bundle created without negative refspecs
(e.g., `new`, but not `old..new`).
If you want to match `git clone --mirror`, which would clone other
refs such as `refs/remotes/*`, use `--all`.
If you want to provide the same set of refs that a clone directly
from the source repository would get, use `--branches --tags` for
the `<git-rev-list-args>`.

因此$ git bundle create repo.bundle --branches --tags最适合克隆。

$ git bundle create repo.bundle --all 将提供源计算机的镜像,包括它的远程引用。

Answers:


189

什么是正确的调用:

  • 捆绑当前仓库中的所有分支

简单:

$ git bundle create repo.bundle --all

repo.bundle是您要创建的捆绑文件的名称。请注意,它--all不包括远程跟踪分支……就像普通克隆一样。

  • 在目标目录上启动新存储库,即正确安装根提交

首先,clone就是init+ fetch(+ administrativia)。

其次,您可以在可使用存储库URL的任何地方使用捆绑文件,因此您可以简单地clone从捆绑文件中使用:

$ git clone repo.bundle

这将创建repo为git存储库。


6
谢谢,--all选项不在我的手册页中bundle(我正在查看版本1.7.6.msysgit.0),也没有在URLs部分使用.bundle文件clone。它使我更有信心推荐使用它。
菲利普·奥克利

20
create命令的概要是git bundle create <file> <git-rev-list-args>。跑步man git-rev-list(或跑步man git-log)会给你--all。但是我同意应该在bundle命令文档中更清楚地看到它。
JakubNarębski2012年

1
我看到在“指定引用”下的捆绑手册页说,“将仅打包由git show-ref” 显示的引用,其中不包括git-rev-list选项。
菲利普·奥克利

2
@Philip Oakley:这git-rev-list-args选择git show-ref命令显示的引用的方式。
JakubNarębski2012年

2
--all确实为我提供了远程跟踪分支(git 2.1.4)。我可以refs/remotes/origin/*git bundle list-heads bundlefile或看到git ls-remote bundlefile。尽管将它们从捆绑包中取出来并不困难。
Alex

32

首先克隆存储库,并包括该--mirror选项。

git clone --mirror git@example.org:path/repo.git

这样可以确保所有远程分支机构也是准备进行捆绑的本地分支机构。

然后跑

git bundle create repo.bundle --all 如雅各布·纳伦斯基(JakubNarębski)的回答所述


3

我建议您将tar或zip文件压缩或压缩,然后将其解压缩到新位置,然后再执行git reset --hard HEAD。所有分支所需的所有内容都在.git下,而您需要做的只是调整.git / config文件中的任何遥控器或将其删除。

tar cf myrepo.tgz .git
cp myrepo.tgz [USB_STICK]
... move to new machine ...
mkdir myrepo && cd myrepo
tar xpf [USB_STICK]/myrepo.tgz
git reset --hard HEAD

4
一个警告是,您需要查看.git / config文件以检查原始回购所有者是否在其中包含任何用户特定的东西。
努法尔·易卜拉欣

@patthoyts:假设它已断开连接,就不会有遥控器;-)确实好像捆绑包(可能)缺少一个选项,并且可能克隆了(需要考虑从捆绑中克隆)
菲利普·奥克利
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.