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 答案后,我这样做了
git bundle create ~/abc.bundle --all
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 ....
git clone -b master ~/abc.bundle ~/newrepo/xyz/
但是当我尝试在 eclipse 中导入这个 git repo 时,我只得到 master 分支,就像在克隆时我使用 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/