克隆git-svn中的trunk之后克隆分支的最佳方法是什么?

时间:2013-03-13 12:49:10

标签: git 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/*

此时,我能够做到:

  1. 提取分支playground的修订版23456

    $ git svn fetch -r 23456

  2. 创建一个本地分支并切换到它

    $ git checkout -b playground branches/playground

  3. 拉入最新的更改:

    $ git svn rebase


  4. 选项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 ,但我真的想知道最合适的方法。

1 个答案:

答案 0 :(得分:4)

您注意到的所有选项都是有效的,并且没有一种“规范”方法可以做到这一点,部分原因是(从git svn的角度来看)没有一种规范的方式来布置Subversion存储库。

您选择的选项1和3基本上是等效的。就个人而言,我已经选择了3,但结果将与您的选项1相同。

选项2可以工作,但它会阻止Git检测跨越分支的提交历史--Git通常会尝试检测合并或创建分支的Subversion提交,并在Git提交中记录这些,但它不能做如果它将两个分支视为完全独立的存储库。

也就是说,通过仅在以后添加新分支,您已经失去了很多历史。请考虑以下流程:

  • 您的Git存储库仅包含git svn次提取的中继。
  • 有人从主干创建游乐场分支,在该分支中进行一些提交,然后将游乐场合并到主干。
  • 您使用git svn获取中继线;它看到了合并,但对playground分支一无所知,将它作为常规提交添加到Git存储库。

如果你一直在挑选游乐场分支,Git会检测到分支并合并,并将其记录下来。之后添加playground分支将无济于事,除非您使用git svn reset重新获取所有提交,因为git svn将不会重写旧提交以记录合并。

正如Chronial在评论中所建议的那样,我所做的就是立即克隆所有分支。这是一个缓慢的过程(我用100,000个提交Subversion存储库,包含近300个分支和标签),这可能需要几天时间才能完成,但你可以将它留在后台,当它完成时你将会拥有完整的Subversion历史记录。

相关问题