将两个 SVN 存储库迁移到 Git 时无法合并现有存储库



我最初在SVN上有一个名为repo A的存储库。让我们将其初始提交称为"提交#1"。我向这个回礼包进行了多次提交,以提交#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-nonrelated-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

现在,这两个存储库中的每一个都有一个主节点,对吧?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 相关,因为它最初应该存在。玩得开心。

最新更新