假设有一个包含许多分支的大型Subversion仓库,我想通过首先克隆trunk
并稍后添加特定分支来开始使用git-svn
。 我看到了至少三种方法来做到这一点,但是它们中有哪些是“官方”的或者是否有最佳方法?
假设以下布局:
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:我也看到有人在现有的远程中添加了一个新的fetch:
[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,但我真的想知道最恰当的做法。