2017-09-03 66 views
0

Git版本控制下我們有幾個不同的Maven項目。現在,我想將這些項目合併爲聚合POM下的maven多模塊項目,併爲此多模塊項目創建一個新的存儲庫。Git,如何結合多個項目保留歷史,不使用子模塊

但是,我不想失去這些彙總項目的歷史。我嘗試爲聚合項目初始化一個新的存儲庫,並克隆工作樹下的現有存儲庫。然而,這些子庫隱含地被認爲是git子模塊,並且我不是git子模塊API的粉絲。我認爲這對其他開發者來說太晦澀難懂了,而且事實太複雜而沒有真正需要。

我想只是將這些存儲庫中的歷史記錄以某種方式合併到新的集合存儲庫中。我不想在合併歷史記錄後與原始存儲庫同步,只是版本控制在沒有子模塊的新聚合存儲庫下的所有內容。不過,我想簽出任何合併存儲庫的特定提交。

這可能在Git中嗎?

+0

您是否得到了可幫助您解決問題的答案?如果是,您可以將其標記爲答案。而且這也會使其他有類似問題的人受益。 –

回答

1
  1. 初始化一個新的回購。

  2. 從所有幾個項目中複製所需版本的文件並將它們組合在一起。如有必要,您可以重新排列目錄結構。並確保文件有預期的內容。

  3. 設置.gitignore,.gitattribute等。將它們全部添加併爲新的回購做出第一次提交。

  4. 從幾個項目中獲取分支並將它們全部與選項-s ours合併。策略僅合併歷史,而不包含真實內容。

例子:

比方說,我們有RepoA,RepoB和RepoC,都包含分支master。我們將合併三個分支的最新版本的文件。現在

git init RepoABC 
cd RepoABC 
#copy the files all RepoA, RepoB, RepoC and rearrange the directory structure if necessary. 
#add .gitignore, .gitattribute, etc if necessary. 
git add . 
git commit -m 'new root for combining RepoA RepoB and RepoC' 
git fetch origin_repoa master:repoa_master 
git fetch origin_repob master:repob_master 
git fetch origin_repoc master:repoc_master 
git merge repoa_master repob_master repoc_master -s ours -m 'Merge and preserve the histories of RepoA, RepoB and RepoC, with merge strategy "ours"' 

我們可以專注於新的回購的分行進行新的變化。歷史是保留的,我們可以回顧他們。如果目錄結構已重新排列,那麼當我們第一次簽出舊提交時,我們可能會遇到一個小問題。作爲未跟蹤文件簽出後,新的文件夾和文件將保留。 git clean -df會跳過它們,所以我們必須rm -rf他們一次。

1

是的,它可能在git中。

假設有兩個回購/項目需要結合起來,併爲每個回購,也有不同的分支:

Repo1:masterdev1

Repo2:masterdev2

在新回購,您可以將項目與以下命令結合在一起:

git init 
# make changes and commit on master branch if you want to combine the aggregated projects in non-master branch 
git remote add repo1 <URL for repo1> -f 
git remote add repo2 <URL for repo2> -f 
git checkout -b repo1_master repo1/master 
git checkout -b repo1_dev1 repo1/dev1 
git checkout -b repo2_master repo2/master 
git checkout -b repo2_dev2 repo2/dev2 

現在repo1和repo2中的所有分支都彙總在分支中的新建回購庫中:repo1_masterrepo1_dev1repo2_masterrepo2_dev2。如果您不需要再次從repo1和repo2進行更改,則可以卸下遙控器:

git remote rm repo1 
git remote rm repo2 
相關問題