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

标签 git svn git-svn

我正在使用 git-svn 来处理 svn 存储库。我不想要整个 repo 协议(protocol),因为它包含很多遗产,其中包含二进制文件。我只跟踪一些目录。

这是我当前的 .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 来完成,但我不想走那条路。

最佳答案

对于每个 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 从添加的分支中获取修订。

你的配置应该是这样的:

[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 将只获取必要的修订。

关于git - 在同一 svn-remote 中初始提取后添加 git 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13376917/

相关文章:

git svn show-ignore 给出错误 "command returned error: 1"

windows - sysopen 权限被拒绝

java - Heroku - Java Maven 项目 depoly - 完成 git Push heroku master 后出现应用程序错误

java - 当为 JComponent 使用本地文件时,有没有办法不对文件路径进行硬编码?

git - 使用 'pull'或 'merge' merge 本地分支?

objective-c - 如何将现有的 XCode (4.5) 项目添加到 BitBucket

git工作流程: how to integrate and test feature branches without continuous delivery?

eclipse - SVN/Eclipse "Show Annotations"——如何将其设置为默认值

svn - 颠覆状态码 404

branch - git-svn branch - 如何使分支与主干保持同步?