git-svn: 迁移具有不同层级分支的 SVN 存储库

git-svn: Migrating a SVN repository with branches in different hierarchical levels

我正在迁移公司中的很多 Git 存储库,一切都很好,直到我遇到一个具有非常特定分支布局的存储库:

/trunk/
/branches/
/branches/lvl1branch1
/branches/lvl1branch2
/branches/lvl1branch3
/branches/lvl2/lvl2branch1
/branches/lvl2/lvl2branch2
/branches/lvl2/lvl2branch
/branches/lvl2/lvl3/lvl3branch1
/branches/lvl2/lvl3/lvl3branch2
/branches/lvl2/lvl3/lvl3branch3
/tags/

如您所见,我们不仅在 /branches/ 的顶层有分支(例如 lvl1branch1),而且只有在其他两个级别(例如 lvl2/lvl2branch1lvl2/lvl3/lvl3branch3)。

这是我的.git/config:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[svn-remote "svn"]
    url = https://myrepourl/
    fetch = test/trunk:refs/remotes/origin/trunk
    branches = test/branches/*:refs/remotes/origin/*
    branches = test/branches/lvl2/*:refs/remotes/origin/lvl2/*
    branches = test/branches/lvl2/*/*:refs/remotes/origin/lvl2/*/*

当我尝试 运行 git svn fetch 命令时出现此错误:

致命:update_ref 引用失败 'refs/remotes/origin/lvl2/lvl3/lvl3branch1':无法锁定引用 'refs/remotes/origin/lvl2/lvl3/lvl3branch1':'refs/remotes/origin/lvl2/lvl3' 存在;无法创建 'refs/remotes/origin/lvl2/lvl3/lvl3branch1' update-ref -m r1638 refs/remotes/origin/lvl2/lvl3/lvl3branch1 e421f7d976832aa2efe84da02378e7f89eb55c26:命令返回错误:128

我可以看到我可以创建分支 lvl2/lvl3/lvl3branch1 因为 Git 正在考虑 lvl2/lvl3 是一个分支,这是不正确的。可能是 .git/config 中的以下行导致了问题:

branches = test/branches/RT-Delivery/*:refs/remotes/origin/lvl2/*

如何告诉 Git 避免将 lvl2/lvl3 读作分支?我相信我也会遇到与 lvl2 相同的问题,它不是一个分支。有没有办法添加例外?

我找到了一个解决方案,我们也可以使用通配符 (*) 来过滤目录名称。这里是 .git/config:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[svn-remote "svn"]
    url = https://svn.it.volvo.net/svn/rtdms_tools/
    fetch = test/trunk:refs/remotes/origin/trunk
    branches = test/branches/lvl1*:refs/remotes/origin/*
    branches = test/branches/lvl2/lvl2*:refs/remotes/origin/lvl2/*
    branches = test/branches/lvl2/lvl3/*:refs/remotes/origin/lvl2/lvl3/*

例如,为了确保我们只会得到第一层的分支(以"lvl1"开头的分支),而不是

branches = test/branches/*:refs/remotes/origin/*

我们可以使用

branches = test/branches/lvl1*:refs/remotes/origin/*