如何使两个git repos相同

时间:2017-04-05 09:53:38

标签: git gitlab

我在两个单独的gitlab部署中有两个git repos和相同的代码。它不是gitlab EE所以我没有镜像功能可供我使用。

一开始我确保每个提交都被推送到两个回购,但随着时间的推移,它失控了,我可以公平地对待这种做法。

目前,我强烈希望repo1repo2相同。但在这样做的过程中,我似乎陷入了困境。

这就是我的所作所为:

$ git pull repo1 master
...there are conflicts. 
...I resolve them, add the file, then do git rebase --continue
$ git push repo1 master --now this works
$ git pull repo2 master
...there are conflicts. 
...I resolve them, add the file, then do git rebase --continue
$ git push repo2 master

在上述之后,我会想象一切都好。但现在当我git pull repo1 master时,我必须重新执行上述步骤。

问题

除了从gitlab删除repo1并重新开始之外,有没有办法强制repo1repo2相同?

此外,还有什么是保持两个回购同步的最佳方式?

2 个答案:

答案 0 :(得分:0)

是否真的有必要拥有那两个完全相同的回购? 如果是,则更容易从本地推送到repo1然后从repo1推送到repo2(例如使用git post-receive hook)

但是现在您可以尝试force push git push -f )来覆盖repo1中的提交历史记录。 (假设repo2包含“正确”历史记录并且repo1包含错误的历史记录):

$ git pull repo2 master
... if there are conflicts, take versions from remote (repo2)
$ git push -f repo1 master

答案 1 :(得分:0)

来自repo1:

git remote add repo2 <path to the other repo>
git checkout master
git fetch repo2
git reset --hard repo2/master

为每个你有兴趣制作相同的分支(可能只是主分支和开发分支?)执行此操作。