首页 > 解决方案 > 复制一个 git 存储库并分成两部分

问题描述

我的团队目前使用一个 TFS Git 存储库来进行开发(网络/移动)和测试(小黄瓜规范 + 自动化代码)。

开发团队“遵循” git flow 分支约定,但测试团队使用完全不同的分支(它们永远不会重新设置或与 feature/develop/rc/master 或我们的任何开发分支合并),所以我们想拆分存储库,保持历史记录和分支原样。

我尝试了将远程 URL 更改为新的 TFS Git 存储库并推送的第一个选项。但这只会推动我当前的分支。所以我尝试了第二个选项

git clone --mirror current_repo_url
git push --mirror new_repo_url

一切看起来都一样,我有整个历史。但是现在我读到 SO 上的其他人正在使用 git filter-branch 和其他“复杂”命令执行此操作,是否需要?和我做的镜子有什么区别?“镜像”是否意味着这些存储库将永远同步并且不能独立更改?

稍后我们将使用该测试 repo 作为 dev repo 的子模块,每个团队将清理其未使用的分支,但现在我们只想要无忧的迁移(基本上更改 remote-url 就是这样),所以我做的很好?

编辑 :

我没有注意到它,但是 push --mirror 最后返回了以下错误,知道这些参考是什么吗?

! [remote rejected]     refs/pull/2616/merge -> refs/pull/2616/merge (The current action can only be performed by the system.)
 ! [remote rejected]     refs/pull/2625/merge -> refs/pull/2625/merge (The current action can only be performed by the system.)
 ! [remote rejected]     refs/pull/2655/merge -> refs/pull/2655/merge (The current action can only be performed by the system.)
 ! [remote rejected]     refs/pull/2668/merge -> refs/pull/2668/merge (The current action can only be performed by the system.)

标签: git

解决方案


...我们想拆分存储库,保持历史记录和分支不变。

您所做的将起作用,并且没有问题。

其他选项:

filter-branch

如上所述,您还可以使用filter-branchwhich 将导致变基,因为它将更新旧的提交

subtree split

# split the "main repo" into smaller repos
git subtree --split .... <branch1>

git subtree --split .... <branch1>命令将“提取”对给定文件夹所做的所有提交,并将它们放置在新分支中。分支将包含给定路径的所有内容。这也将导致变基,因为历史将被重写

在此处输入图像描述


推荐阅读