2017-04-05 81 views
0

我有两个git仓库在两个单独的gitlab部署上使用相同的代码。这不是gitlab EE,所以我没有提供给我的镜像功能。如何使两个git仓库相同

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

目前,我会强制要使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时,我必须再次执行上述步骤。

问题

有没有办法强行让repo1一样repo2比gitlab删除repo1并启动了其他?

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

回答

0

真的有必要让这两个确切的回报相同吗? 如果是的话,它会更容易只推到当地repo1,然后按从repo1到repo2(例如用一个git后收到钩)

但现在你可以尝试force push混帐推-f)覆盖repo1中的提交历史记录。 (假设repo2包含了“正确”的历史和repo1错了):

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

从repo1:

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

这样做对你有兴趣在做同样的每个分支(可能只是主人和发展部门?)。