2011-05-09 160 views
2

我有兩個git倉庫,每個倉庫都包含相同代碼庫的不同版本。合併兩個git倉庫,保留所有提交歷史

犯回購1(最近的最後一次):

version 1 
version 2 
version 3 
version 4 
version 5 

犯回購2:

version 3 
commit that isn't a new version 
another commit that isn't a new version 
yet another commit that isn't a new version 
version 5 

注意,在回購1,第5版是基於版本4,但在回購2,版本4不存在,因爲版本5確實基於版本3(並且版本4本質上變成了被遺棄的分支)。

我喜歡把所有這一切都爲一個回購協議:

version 1 
version 2 
version 3 
    branch version 4 
commit that isn't a new version 
another commit that isn't a new version 
yet another commit that isn't a new version 
version 5 

我會很感激,如果有人可以解釋不僅如何做到這一點,但爲什麼它是正確的做這樣,我可以更好地理解git。

回答

1

看看git rebase --preserve-merges --onto。將第二個回購的提交提交到第一個回購後,您可以移動部分歷史記錄以擁有您想要的祖先。

希望這會有所幫助。

編輯:

要想從第二回購的變化,將其添加爲遠程:

git remote add secondary <url to your secondary repo> 

然後你就可以從中獲取:

git fetch secondary 

現在你可以檢查gitk --allgit log --all --graph --decorate --oneline,並做你喜歡的rebase --onto

+0

您應該包括如何從第二個回購提交到第一個提交;這將使這個很棒的答案。 – ebneter 2011-05-09 23:32:25

+0

完成。希望這是足夠的信息。 – 2011-05-09 23:42:13

相關問題