在同一个svn-remote中初始获取后添加git分支

时间:2012-11-14 10:19:56

标签: git svn git-svn

我正在使用git-svn来处理svn repo。我不想要整个回购,正弦它包含很多遗产,其中包含二进制文件。我只跟踪一些目录。

这是我当前的.git/config,它运行正常。

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[svn-remote "svn"]
    url = https://svn.example.com/repository
    fetch = trunk/Python:refs/remotes/trunk
    branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*
    branches = branches/{active}/Python/:refs/remotes/*

现在我要添加一个新分支:

    branches = branches/{fuze_node}/:refs/remotes/*

但是在执行git svn fetch时,git看不到新分支。它就像行不在配置中一样。


我知道这可以用一个新的svn-remote来完成,但我宁愿不采取这条道路。

2 个答案:

答案 0 :(得分:20)

对于每个svn-remote git-svn,将最新提取的修订存储在.git/svn/.metadata文件中。它永远不会取得低于该值的修订。这就是为什么它不会获取你添加到配置中的分支; git-svn认为fuze_node分支已经转换。

但是,您可以获取此分支,而无需再次重新克隆整个存储库:

  1. 添加另一个svn-remote,其中包含您需要获取的所有分支;
  2. 删除旧的svn-remote;
  3. 运行git svn fetch -R newer-svn-remote以从添加的分支中获取修订。
  4. 您的配置应如下所示:

    [core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
    # [svn-remote "svn"]
    #    url = https://svn.example.com/repository
    #    fetch = trunk/Python:refs/remotes/trunk
    #    branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*
    #    branches = branches/{active}/Python/:refs/remotes/*
    [svn-remote "newer-svn-remote"]
        url = https://svn.example.com/repository
        fetch = trunk/Python:refs/remotes/trunk
        branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*
        branches = branches/{active}/Python/:refs/remotes/*
        branches = branches/{fuze_node}/:refs/remotes/*
    

    请注意,您必须指定与旧版svn-remote完全相同的分支映射:

        branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*
    

    也就是说, refs / remotes / * 仍应位于映射的右侧。否则git-svn无法检测已经转换的提交并尝试再次获取它们。


    实际上还有另一种方法可以实现同样的目标。它涉及对内部git-svn文件的一些操作。

    您可以将必要的分支添加到.git/config并更新.git/svn/.metadata文件,以便最新提取的修订版变为0:

    [svn-remote "svn"]
        reposRoot = https://svn.example.com/repository
        uuid = 8a6ef855-a4ab-4527-adea-27b4edd9acb6
        branches-maxRev = 0
        tags-maxRev = 0
    

    之后git svn fetch将仅获取必要的修订。

答案 1 :(得分:0)

我找到了一种更简单的方法,它不需要编辑任何配置文件。

您只需要要添加到本地 git-svn 存储库的分支中最后一次提交的修订号。

如果你有新分支的 SVN checkout 并且安装了 TortoiseSVN,你可以右键点击这个文件夹并使用“TortoiseSVN / Show Log”。

记下最上面的提交(例如 45065)。

现在在 Git Bash 中使用以下命令:

git svn fetch -r45065

注意:您需要将编号 45065 替换为您的提交编号。
git 现在会将新的远程分支拉入您的本地存储库。

然后您可以通过创建本地分支来检查它。我正在使用 Git 扩展来检查新分支,使用“远程分支”和选项“使用名称创建本地分支:...”。
提示:您可以从本地分支名称中删除“origin/”前缀,因为这样可以避免警告“refname 'origin/V8.0' is ambiguous。”。