簡體   English   中英

將兩個 SVN 存儲庫遷移到 Git 時無法合並現有存儲庫

[英]Can't merge existing repo when migrating two SVN repos to Git

我最初在 SVN 上有一個名為 repo A 的 repo。讓我們稱其為初始提交“commit #1”。 我對這個 repo 做了多次提交,讓我提交 #3。 此時,我將 SVN 存儲庫復制到 SVN 上的新位置,並在復制的存儲庫 B 中繼續開發。同時,我也繼續致力於存儲庫 A。

下面描述了 SVN 存儲庫的樣子:

Repo A: 1-2-3-4a-5a-6a
             \
Repo B:       4b-5b-6b

現在,在這一點上,我決定將兩個存儲庫移至 Git。 我的目的是克隆兩個存儲庫,然后將它們重新加入一個存儲庫,將單獨的提交維護為從上面的提交 #3 發芽的單獨分支。

所以,我執行了以下步驟:

git svn clone -s -A svn.authors --no-metadata http://subversion.foo.local/repoA_svn/path repoA
git svn clone -s -A svn.authors --no-metadata http://subversion.foo.local/repoB_svn/path repoB
cd repoA
git branch repoA-branch # Branch for first repo
git reset --hard <highest_common_hash> # To have only common history on master
git checkout -b repoB-branch # Branch for second repo
git pull ../repoB master

但是,一旦我嘗試執行拉取操作,就會出現以下錯誤:

fatal: refusing to merge unrelated histories

在從 SVN 遷移時,因為我之前已經移動了 SVN 上的 repoB 位置以將其與 repoA 分開,因此與 repoA 的鏈接丟失了。

所以我有兩個從 SVN 遷移的 Git 存儲庫,如下所示:

Repo A: 1-2-3-4a-5a-6a
.
Repo B:       4b-5b-6b

如您所見,鏈接已斷開,因此不相關的歷史記錄錯誤。

鑒於我們缺少歷史鏈接,有誰知道如何將 repoB 的提交添加到 repoA?

我在拉取期間嘗試了 --allow-unrelated-history 開關,它允許我添加 repoB 的提交,但它們都被壓縮為一個,我想保留這些提交的歷史記錄。

為了簡單起見而不是回到不得不在 svn 上做任何事情,我會這樣做:

# create a new third repo
git init /home/myuser/blahblah
cd /home/myuser/blahblah
# add thr other two git repos as remotes
git remote add repo1 whatever-url-for-repo1
git remote add repo2 whatever-url-for-repo2

現在,這兩個 repos 中的每一個都有一個 master,對嗎? 而repo2/master是從repo1/master的第三版開始的吧?

git checkout first-revision-of-repo2/master # checkout this revision by id
git reset --soft third-revision-of-repo1/master # this revision is also by its id
git commit -m "Same comment as repo2/4b"

此時您已經創建了 4b'。 它與 4b 的內容相同,它的父版本為修訂版 3

# now we roll all the other revisions from 4b to the tip of repo2/master
git cherry-pick revision-4b..repo2/master # original ID of revision 4b on repo2/master

在這一點上,您現在在新分支上擁有 repo2/master 的歷史記錄(仍未命名,您正在處理分離的 HEAD)並且它與 repo1/master 相關,因為它最初應該存在。 玩得開心。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM