我正在使用 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
分支已经转换。
然而,您可以获取此分支而无需再次重新克隆整个存储库:
- 添加另一个 svn-remote,其中包含您需要获取的所有分支;
- 删除旧的 svn-remote;
- 运行
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/