如何告诉git-svn关于在获取回购后创build的远程分支?
我使用git-svn来对付我公司的中央svn仓库。 我们最近在中央回购中创build了一个新的function分支。 我该如何告诉git ? 当我运行git branch -r我只能看到当我对svn repo执行fetch以初始化我的git repo时存在的分支? 
您可以手动添加远程分支,
 git config --add svn-remote.newbranch.url https://svn/path_to_newbranch/ git config --add svn-remote.newbranch.fetch :refs/remotes/newbranch git svn fetch newbranch [-r<rev>] git checkout -b local-newbranch -t newbranch git svn rebase newbranch 
如果你想跟踪所有的远程svn分支,那么解决scheme就像下面这样简单:
 git svn fetch 
这将获取尚未被提取的所有远程分支。
 额外提示:如果您首先检出了主干,后来又想跟踪所有分支,那么编辑.git/config看起来像这样,然后重新运行git svn fetch : 
 [svn-remote "svn"] url = https://svn/path_to_repo_root/ fetch = path_to_trunk:refs/remotes/git-svn branches = path_to_branches/*:refs/remotes/* 
 关键点是url应该指向版本库的根目录,在fetch和branches定义的path应该是相对于url 。 
 如果你只想获取特定的分支而不是ALL,那么在git svn --help有一个很好的例子: 
 [svn-remote "huge-project"] url = http://server.org/svn fetch = trunk/src:refs/remotes/trunk branches = branches/{red,green}/src:refs/remotes/branches/* tags = tags/{1.0,2.0}/src:refs/remotes/tags/* 
 使用老版本的git-svn ,一旦你指定了这样的分支,你可能无法使用git svn fetch获取新分支。 一种解决方法是添加更多的fetch线,如下所示: 
 [svn-remote "huge-project"] url = http://server.org/svn fetch = trunk/src:refs/remotes/trunk fetch = branches/blue:refs/remotes/branches/blue fetch = branches/yellow:refs/remotes/branches/yellow branches = branches/{red,green}/src:refs/remotes/branches/* 
 另一个由@AndyEstes解决的方法:编辑.git/svn/.metadata并在创build任何新指定的分支或标记之前,将branches-maxRev或tags-maxRev的值更改为修订版。 一旦你完成了这个,运行git svn fetch来跟踪新的svn远程分支。 
 看来我只需要git svn fetch ; 不知何故,我已经相信自己会取得整个回购,而不仅仅是变化。 
也许我搞砸了,但我按照vjangus的答案指示,它几乎工作。 唯一的问题是,新生枝似乎没有从树干分枝。 在gitk中,它是一种“漂浮”的东西。 它与树干没有共同的祖先。
解决scheme是:
- 在创build分支之前查找发生在主干上的最后一次提交的SHA1。
- find新分支上的第一个提交的SHA1(消息可能是“创build新的分支,从trunk @ 12345复制的东西)
-   git diff-tree <sha1 from step 1> <sha1 from step 2>– 应该没有输出。 如果有输出,则可能select了错误的提交。
-   git checkout local-newbranch然后git rebase <sha1 from step 1>。 这将重新将local-newbranch转移到新树上,但remotes/newbranch新remotes/newbranch仍然会断开连接。
-  转到文件.git/refs/remotes/newbranch并对其进行编辑,以包含与当前指向的旧提交对应的新提交(位于rebased的新newbranch)的完整SHA1。 (或者可能使用git-update-ref refs/remotes/newbranch <new-SHA>,谢谢你。
-  下一次你把git svn dcommit移到newbranch,你会得到一堆关于更新日志的消息。 我认为这是正常的。
 我build议保持gitk --all打开整个时间,并经常刷新,以跟踪你在做什么。 对于git和git svn,我还是有点新意,所以请build议对此方法进行改进。 
我还没有find任何有关此function的文档,但看起来像git svnconfiguration支持多个提取条目。 这样你也可以单独添加分支,而不需要为你的configuration添加另一个远程的svn仓库条目,也不需要使用通配符来获得特定目录的所有分支。
假设你的SVN树真的很讨厌有很多没有任何逻辑的分支,例如它们的分支和子目录包含更多的分支。
即
 trunk branches -> branch1 -> sub-dir1 -> branch2 -> branch3 -> sub-dir2 -> branch4 -> sub-dir3 -> branchX <... hundreds more ...> 
而你只是想要select一些要包含到你的git仓库的分支。
您可以首先启动您的存储库只有中继没有任何额外的分支机构:
 git svn clone -r 10000:HEAD https://svn.com/MyRepo myrepo --prefix=svn/ --trunk=trunk 
之后,你应该看到以下configuration:
 localhost: elhigu$ git config --get-regexp "svn-remote." svn-remote.svn.url https://svn.com/MyRepo svn-remote.svn.fetch trunk:refs/remotes/svn/trunk 
当你想要从MyRepo获取新的分支时,你可以通过以下方式添加新的获取条目到configuration:
 git config --add svn-remote.svn.fetch branches/sub-dir2/branch4:refs/remotes/svn/branches/sub-dir2/branch4 
或者您可以在.git / config中编辑相同的configuration
将它们添加到configuration后运行,以获取新分支:
 git svn fetch -r 10000:HEAD 
[编辑]有时似乎有必要使用–all参数来获取新添加的分支:
 git svn fetch --all -r 10000:HEAD 
而不是处理git-svn怪癖,你可以尝试SubGit 。
一个必须安装SubGit到Subversion版本库。 之后,可以使用标准的git工作stream程,而不是使用特殊的git-svn命令:
- 
推新提交: 混帐SVN: $ git commit $ git svn rebase $ git svn dcommitSubGit: $ git commit $ git push
- 
获取传入的更改 混帐SVN: $ git svn rebaseSubGit: $ git pull [--rebase]
- 
创build一个新的分支: 混帐SVN: $ git svn branch foo $ git checkout -b foo -t remotes/foo $ git commit $ git svn dcommitSubGit: $ git checkout -b foo $ git commit $ git push
有关更多详细信息,请参阅SubGit文档 。
简化vjangus的答案:
如果你在SVN中使用标准布局,并且完成了通常的svn init,那么git-svn会为你做configuration。 只是:
- 在SVN中查找分支版本
- 用git-svn取得该版本
- 创build新的本地分支跟踪远程
 一个例子。  SVNurl是svn+ssh://gil@svn.myplace.com/repo 。 我正在寻找的SVN分支是newbranch 。 本地git分支(跟踪远程newbranch )将git-newbranch 。 
步骤1:find分支副本修订
     #svn log --stop-on-copy svn + ssh://gil@svn.myplace.com/repo/branches/newbranch |  尾巴-4
     r7802 | 某人|  2014-03-21 18:54:58 +0000(2014年3月21日星期五)|  1行
    将HEAD分支到newbranch
     -------------------------------------------------- ----------------------
所以SVN中的分支点是修订版7802。
第2步:获取修订
     #git svn fetch -r 7802
    find可能的分支点:svn + ssh://gil@svn.myplace.com/repo/trunk => svn + ssh://gil@svn.myplace.com/repo/branches/newbranch,7801
    find分行家长:(refs / remotes / trunk)8dcf3c5793ff1a8a79dc94d268c91c2bf388894a
    继父母后,do_switch
    成功跟随父母
     r7802 = 9bbd4194041675ca5c9c6f3917e05ca5654a8a1e(参考/遥控器/ newbranch)
git-svn完成了所有的工作,现在知道了远程:
     #git show-ref |  grep newbranch
     2df23af4733f36f5ad3c14cc1fa582ceeb3edb5c refs /遥控器/ newbranch
第3步:创build新的本地分支,跟踪远程分支:
     #git checkout -b git-newbranch -t newbranch
    检出文件:100%(413/413),完成。
    分支git-newbranch设置为跟踪本地ref refs / remotes / newbranch。
    切换到一个新的分支'git-newbranch'
要添加到vjangus的答案,这有助于我,我也发现添加使用git移植将分支绑定到主干在适当的位置是有用的 – 允许git查看历史logging并正确执行合并。
 这只是使用散列向.git/info/grafts添加一行的情况: 
 <initial branch commit> <parent commit in trunk> 
例如。
 378b0ae0902f5c2d2ba230c429a47698810532e5 6c7144991381ce347d4e563e9912465700be0638 
感谢http://evan-tech.livejournal.com/255341.html
(我会添加这个评论,但是我没有足够的声望。)
如果你没有签出一个有效的布局,你将无法签出远程分支。
这就是我所做的:
 git svn init -s <svn path with no trunk> local_repo cd local_repo git svn fetch ## wait 
之后,您可以切换到远程分支:
 git checkout --track -b branch_name branch_name 
然后你会自动切换到你的分支。