[英]What is the best way to clone branches after cloning just trunk in git-svn?
给定一个包含许多分支的大型Subversion存储库,我想先开始使用git-svn
克隆trunk
然后再添加特定的分支。 我看到至少有三种方法可以做到这一点,但是他们中的任何一种都是“官方的”还是有最好的办法?
假设以下布局:
https://svn-repo.com/svn/company
+--core
| +--trunk
| +--branches
| | +--fastboot
| | +--playground
| +-tags
+--mobile
+--trunk
+--branches
+--tags
因此,仅克隆项目core
的主干(无分支)修订版12345:
$ git svn clone --username=svnuser -r 12345 -Ttrunk https://svn-repo.com/svn/company/core
这会将项目core
克隆到同名目录中并运行git svn rebase
将引入所有更改(在修订版12345之后)。 此时.git/config
应该包含这样的内容:
[svn-remote "svn"]
url = https://svn-repo.com/svn/company
fetch = core/trunk:refs/remotes/trunk
到现在为止还挺好。 现在,假设我要添加playground
分支。 这是它有点模糊的地方。
选项1 :通过在那里添加分支来更新.git/config
的现有远程:
[svn-remote "svn"]
url = https://svn-repo.com/svn/company
fetch = core/trunk:refs/remotes/trunk
branches = core/branches/{playground}:refs/remotes/branches/*
此时,我能够做到:
拉入分店playground
23456号修订版
$ git svn fetch -r 23456
创建一个本地分支并切换到它
$ git checkout -b playground branches/playground
拉入最新的变化:
$ git svn rebase
选项2 :在.git/config
添加新的远程(除了现有的远程):
[svn-remote "playground"]
url = https://svn-repo.com/svn/company
fetch = core/branches/playground:refs/remotes/playground
从这里开始,步骤类似于选项1中的步骤:
$ git svn fetch playground -r 23456
$ git checkout -b playground remotes/playground
$ git svn rebase
选项3 :我还看到有人在现有的遥控器中添加了一个新的提取:
[svn-remote "svn"]
url = https://svn-repo.com/svn/company
fetch = core/trunk:refs/remotes/trunk
fetch = core/branches/playground:refs/remotes/branches/playground
我不完全确定这是否正确或是否可行。 我找不到我看到的地方。
目前,我坚持使用选项1 ,但我真的想知道最合适的方法。
您注意到的所有选项都是有效的,并且没有一种“规范”方法可以做到这一点,部分原因是(从git svn
的角度来看)没有一种规范的方式来布置Subversion存储库。
您选择的选项1和3基本上是等效的。 就个人而言,我已经选择了3,但结果将与您的选项1相同。
选项2可以工作,但它会阻止Git检测跨越分支的提交历史--Git通常会尝试检测合并或创建分支的Subversion提交,并在Git提交中记录这些提交,但如果它是,则它不能这样做将两个分支视为完全独立的存储库。
也就是说,通过仅在以后添加新分支,您已经失去了很多历史。 请考虑以下流程:
git svn
的trunk提取。 git svn
来获取trunk; 它看到了合并,但对playground分支一无所知,将它作为常规提交添加到Git存储库。 如果您一直在拾取游乐场分支,Git会检测到分支并合并,并将其记录下来。 之后添加playground分支将无济于事,除非您使用git svn reset
重新获取所有提交,因为git svn
将不会重写旧提交以记录合并。
正如Chronial在评论中所建议的那样,我所做的就是直接克隆所有分支。 这是一个缓慢的过程(我用100,000个提交Subversion存储库,包含近300个分支和标签)这可能需要几天时间才能完成,但你可以将它留在后台,当它完成时你会拥有完整的Subversion历史记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.