2017-04-05 130 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 

這樣做對你有興趣在做同樣的每個分支(可能只是主人和發展部門?)。