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

时间:2018-10-01 14:20:37

标签: git svn git-svn

我正在公司中迁移许多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 / lvl2branch1 lvl2 / 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 命令时出现此错误:

致命的:ref'refs / remotes / origin / lvl2 / lvl3 / lvl3branch1'的update_ref失败:无法锁定ref'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 也会遇到同样的问题,它不是分支机构。有没有添加例外的方法?

1 个答案:

答案 0 :(得分:2)

我找到了一个解决方案,我们也可以使用通配符(*)来过滤目录名称。这是 .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/*