【发布时间】:2017-12-13 22:32:51
【问题描述】:
我有一些我想要的 git 存储库:
- 端口到新的 git 服务器。
- 向它们添加子模块。
这本身就很简单,问题是我想循序渐进地做到这一点。也就是说,我希望用户继续克隆/拉取/推送到旧存储库,同时将这些提交移植到新存储库。最终,“旧”服务器将被删除,用户将开始使用带有子模块的新服务器。我有一个詹金斯服务器,它将负责每晚将所有这些存储库从旧服务器移植到新服务器。 同样,这将是非常简单的,除了我希望新的仓库有一些旧仓库没有的子模块。所以情况会是这样的:
Old Repo New Repo
| |
CommitA-------->CommitA
| |
| CommitB (Add submodules)
| |
CommitC-------->CommitC
| |
CommitD-------->CommitD
| |
. .
. .
. .
如您所见,我想将所有提交从旧仓库移植到新仓库,但不会丢失任何信息(我不想只是从旧仓库复制源代码并在新仓库中覆盖它们,因为这会丢失 cmets 和中间提交,因为该移植操作将每天执行一次)。
有人可以给我一些关于如何实现这一点的提示,以及我如何在“自动化”模式下执行它(不只是一个一个地挑选提交)。
谢谢!
编辑
所以我一直在尝试,现在我有:
#Clone "New Repo"
git clone ssh://<NewRepoServer>/bitbucket_tests bitbucket_tests
cd bitbucket_tests
#Add "Old Repo" remote
git remote add old_repo <OldRepoServer/bitbucket_tests>;
#update New Repo remote
git remote update origin;
#update Old Repo remote
git remote update old_repo;
#Loop through all branches, and try to merge them
for remote_branch in `git branch -r | grep old_repo | grep -v master | grep -v HEAD | awk '{gsub(/^[^\/]+\//,"",$1); print $1}'`; do
git branch -f --track $remote_branch
git checkout $remote_branch
git pull -s recursive -X patience -X theirs old_repo $remote_branch
git pull
done
git checkout master
git pull -s recursive -X patience -X theirs old_repo master
git pull
#Push results to Old Repo
git push origin refs/remotes/old_repo/*:refs/heads/*;
虽然如果没有对“New Repo”分支进行修改,这可以正常工作,但当 NewRepo 有一些在 OldRepo 中不存在的提交时它会失败(例如上图中的 CommitB):
git push origin 'refs/remotes/old_repo/*:refs/heads/*'
To ssh://<NewRepoServer>/bitbucket_tests
! [rejected] old_repo/testBranch -> testBranch (non-fast-forward)
error: failed to push some refs to 'ssh://<NewRepoServer>/bitbucket_tests'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
如何在无需用户干预的情况下自动将这些更改合并到 OldRepo 的内容中?
【问题讨论】:
标签: git git-branch git-merge git-submodules