![](/img/trans.png)
[英]How to combine two git repos, preserving the history of both, and the hashes of one?
[英]How to combine two git repos into one repo in parent folder?
我在同一個父文件夾中有兩個回購協議,我想將它們合並到父文件夾中,如果可能的話,保留歷史記錄而不會出現最小差異。
parent/
--code1/.git
--code2/.git
我想:
parent/.git
--code1
--code2
是否可以這樣做並保留兩者的歷史記錄? 或者至少是 code1 文件夾? 不幸的是,兩個回購協議中都有一些同名分支。 理想的情況是在提交日期之前將兩個歷史都包含在 .git 中,但我還沒有找到一個簡單的解決方案(一個復雜的問題是 git mv 顯示提交之前/之后的差異,所有文件都已更改,但我們可以接受).
您只想將兩個不同的存儲庫(第一個和第二個)合並到一個新存儲庫中,同時保留兩個git歷史記錄:
創建一個新的git倉庫並進行初始提交:
mkdir newRepository
git init
touch .gitignore
git add .gitignore
git commit .gitignore -m 'init'
獲取並合並第一個:
git remote add first pathTo/first
git fetch first
git merge first/master
獲取並合並第二個:
git remote add second pathTo/second
git fetch second
git merge second/master
您應該能夠利用git pull
方法。
請執行下列操作:
$ git init
$ git pull code1
$ git pull code2
這應該創建一個合並。接受合並(如果有,則發生沖突沖突)。
要將分支拉入父git repo,可以執行以下操作:
$ git checkout -b branchName
$ git pull code1 branchName
編輯:我錯過了與您仍然想保留code1
和code2
文件夾的部分。 當合並兩個存儲庫時,這實際上是不可能的,因為它正在按照它說的那樣:將它們合並到父文件夾中。您將必須手動將源文件移至code1
和code2
,然后進行進一步提交。
我遇到了同樣的問題並遇到了這篇文章。 我最終通過在將它們合並在一起之前重組每個回購來解決它
repo1*content -> repo1\repo1newname*content repo2*content -> repo2\repo2newname*content
每個在自己的分支上切斷 HEAD/main
然后我將兩個 repos 作為遙控器添加到新的 repo 並從這些分支中拉出
結果是
新倉庫
..\repo1newname..\repo2newname
重組為每個文件添加了一個重命名提交,因此保留了每個文件的提交歷史,只是多了一個用於重命名的額外提交和另一個用於合並的提交。
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.