具有多个分支位置的 Git-SVN?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1638478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:55:06  来源:igfitidea点击:

Git-SVN with multiple branch locations?

gitgit-svn

提问by Dave Vogt

Our company subversion repo is a bit tricky: We've got a basic "default" layout with trunk, tags and branches. However, inside the branches, we have a "work" directory which contains more branches. Something like this:

我们公司的 subversion repo 有点棘手:我们有一个基本的“默认”布局,包括主干、标签和分支。但是,在分支内部,我们有一个包含更多分支的“工作”目录。像这样的东西:

  • branches/release_1_0_x
  • branches/release_1_1_x
  • branches/work/dave/topic_one
  • branches/work/tom/topic_two
  • branches/work/something_else
  • 分支/release_1_0_x
  • 分支/release_1_1_x
  • 分支机构/工作/戴夫/topic_one
  • 分支/工作/tom/topic_two
  • 分支机构/工作/something_else

Now how can I get git-svn to recognize all those (and a few more) as separate branches? It appears git svn initonly accepts one branch location, how ever I'm invoking it.

现在我怎样才能让 git-svn 将所有这些(以及更多)识别为单独的分支?它似乎git svn init只接受一个分支位置,我如何调用它。

Edit: this is how I initialized the git repo:

编辑:这就是我初始化 git repo 的方式:

git svn clone  -s --prefix=svn/ http://svn.company.com/product/

采纳答案by jamessan

According to the answer to another question, your best bet is to use Git 1.6.x and take advantage of "deep cloning".

根据另一个问题的答案,您最好的选择是使用 Git 1.6.x 并利用“深度克隆”。

If you can't upgrade to 1.6.x, then you can specify multiple branches when you clone.

如果你不能升级到1.6.x,那么你可以在克隆时指定多个分支。

git svn clone -s --prefix=svn/ -b branches -b branches/work/dave -b branches/work/tom ...

You'll just have to make sure you add info for new users to your .git/config before "git svn fetch"ing when a new user branch has been added.

在添加新用户分支时,您只需要确保在“git svn fetch”之前将新用户的信息添加到 .git/config 中。

回答by rcoup

You can add multiple branches and tags entries in your git-svn config, even retroactively. So if normally SVN branches live in branches/*in your SVN repo (ie. a standard layout), but you also have branches/summer-students/*, you can set it up in .git/configlike below:

您可以在 git-svn 配置中添加多个分支和标签条目,甚至可以追溯。因此,如果通常 SVN 分支branches/*位于您的 SVN 存储库(即标准布局)中,但您也有branches/summer-students/*,则可以按.git/config如下方式进行设置:

[svn-remote "svn"]
    url = svn+ssh://svn.example.com
    fetch = trunk:refs/remotes/trunk
    branches = branches/*:refs/remotes/*
    tags = tags/*:refs/remotes/tags/*

    branches = branches/summer-students/*:refs/remotes/svn-summer-students/*

On the left of the :is the path in the SVN Repo, and on the right is the path it will appear as in your git remote branch list. You can use refs/remotes/*repeatedly to have everything appear as a top-level remote branch, but watch out for name collisions - they will break things (hence svn-summer-studentsinstead of summer-students, which already exists).

左侧:是 SVN Repo 中的路径,右侧是它将出现在您的 git 远程分支列表中的路径。您可以refs/remotes/*重复使用使所有内容都显示为顶级远程分支,但要注意名称冲突 - 它们会破坏事物(因此svn-summer-students而不是summer-students已经存在的 )。

After you edit the config, you need to delete .git/svn/.metadataand run git svn fetchto refresh the branch list and regenerate it. git branch -rshould then show the extra branches. If you get errors, look out for naming collisions.

编辑完配置后,需要删除.git/svn/.metadata并运行git svn fetch刷新分支列表并重新生成。git branch -r然后应该显示额外的分支。如果出现错误,请注意命名冲突。

The git svn docshave some more examples of specifying paths via wildcards or expressions if you have a funky SVN layout.

如果你有一个时髦的 SVN 布局,git svn 文档有更多的例子通过通配符或表达式指定路径。

回答by joshwa

For those looking to do this retroactively, the git-svn manpage for 1.7.xsays:

对于那些希望追溯执行此操作的人,1.7.xgit-svn 联机帮助页说:

It is also possible to fetch a subset of branches or tags by using a comma-separated list of names within braces. For example:

也可以通过在大括号内使用逗号分隔的名称列表来获取分支或标签的子集。例如:

[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/*