git 存储库导出和导入到 zip 文件或文件夹

标签 git import repository export egit

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

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

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

我试过了,

git archive HEAD --format=zip >~/abc.zip but while importing back in eclipse its not working.

还有其他方式导入和导出 git 存储库吗?


编辑

查看@VonC 答案后,我这样做了

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

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

      refs/heads/master
      refs/remotes/origin/branch1
      refs/remotes/origin/branch1
      refs/remotes/origin/branch3
      refs/remotes/origin/master 
      refs/remotes/origin/branch4
      .....
      refs/tags/tag1
      refs/tags/tag2
      refs/tags/tag3
       ....

  3. git clone -b master ~/abc.bundle ~/newrepo/xyz/

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

最佳答案

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

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

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


when I tried to import this git repo in eclipse I am getting only master branch as while cloning I used master. Is it possible to clone all the branches in a single command?

在克隆的存储库(从 bundle 中克隆的存储库)中执行 gitbranch -avvv
您应该看到所有远程分支 (origin/xxx)。

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

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

关于git 存储库导出和导入到 zip 文件或文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21983833/

相关文章:

git - 如何以这种特定方式拆分 git commit

git - 如何停止忘记更改每个 git 项目的标识

git - 在 github 上管理发布

python - 谷歌云语音导入错误 : cannot import name 'enums'

csv - 将CSV数据原样放入新CSV

ruby-on-rails - 为开发/测试和生产指定相同的 gem 两次,但路径不同

Python导入

Maven - 完全禁用本地存储库,只转到远程

svn - 从mercurial项目推送到svn项目

macos - Maven 的 settings.xml 在 Mac OS 上位于哪里?