【问题标题】:git repository export and import to zip file or foldergit 存储库导出和导入到 zip 文件或文件夹
【发布时间】:2014-02-24 09:38:40
【问题描述】:

关于 git 存储库导出和导入的 SO 上有一些类似的帖子,但所有答案都不完整。所以我在这里提出单独的问题。

我在 Eclipse 中使用 EGIT 来处理 git SCM。

如何将 git 存储库导出到 zip 文件/文件夹(包含所有分支、标签和历史记录) 并在 Eclipse 中导入相同的存储库?

我试过了,

git archive HEAD --format=zip >~/abc.zip 但在 eclipse 中重新导入时它不起作用。

还有其他方式可以导入和导出 git 仓库吗?


编辑

看了@VonC 的答案后,我做了这个

  1. git bundle create ~/abc.bundle --all

  2. git bundle list-heads ~/abc.bundle

    裁判/负责人/大师 refs/remotes/origin/branch1 refs/remotes/origin/branch1 refs/remotes/origin/branch3 refs/remotes/origin/master refs/remotes/origin/branch4 ...... 参考/标签/标签1 参考/标签/标签2 参考/标签/标签3 ....
  3. git clone -b master ~/abc.bundle ~/newrepo/xyz/

但是当我尝试在 eclipse 中导入这个 git repo 时,我只得到 ma​​ster 分支,因为我在克隆时使用了 master。是否可以在一个命令中克隆所有分支?

【问题讨论】:

    标签: git import repository export egit


    【解决方案1】:

    另一种实际上保留完整历史记录的方法是git bundle(参见“Backup a Local Git Repository”)。

    cd /path/to/your/repo
    git bundle create ../repo.bundle --all
    

    但是,您必须在 EGit 看到导出/导入的 repo 之前再次克隆它,因为EGit doesn't support yet bundle files as repo。


    当我尝试在 eclipse 中导入这个 git repo 时,我只得到 ma​​ster 分支,因为我在克隆时使用了 master。是否可以在一个命令中克隆所有分支?

    在您的克隆存储库(从捆绑包中克隆的存储库)中执行 git branch -avvv。
    您应该会看到所有远程分支 (origin/xxx)。

    Eclipse 应该能够列出并创建一个基于those remote tracking branches 之一的新分支,如“How do I create a proper new local and remote branch combination in EGit?”。

    要从包中恢复所有分支,请参阅“restore all refs from git bundle”:
    你需要镜像克隆它。

    【讨论】:

    • 编辑了我的帖子,添加了详细信息
    • @ChandrayyaGK 我的意思是git branch -avvv,而不是git br(这是我的别名)
    • 没有不行。执行git branch -avvv 然后git branch -a 结果为:
      master remotes/origin/HEAD -> origin/master remotes/origin/master
    • @ChandrayyaGK 然后镜像克隆它:clone --mirror 将包含所有远程跟踪分支。见stackoverflow.com/a/12003661/6309。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多