如何使用具有非标准svn回购布局的git-svn访问svn分支? [英] How do I access svn branches using git-svn with a non-standard svn repo layout?

查看:193
本文介绍了如何使用具有非标准svn回购布局的git-svn访问svn分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

svn中的标准仓库布局如下.

The standard repo layout in svn is as follows.

/trunk
/branches
    featureX
    featureY
/tags
    1.0
    2.0

我正在使用的存储库的结构要平坦得多.

The repository I'm working with is a much flatter structure.

trunk
featureX
featureY

从本质上讲,主干与其他分支处于同一级别.因此,我不能在git svn init中使用-s或-b选项.

Essentially, trunk is at the same level as the other branches. I can't use the -s or -b option with git svn init because of this.

我如何将trunk作为git分支master引入,并将featureX作为同名的git分支引入?我不在乎其他任何分支或标签.

How would I pull in trunk as the git branch master and pull in featureX as a git branch of the same name? I don't care about any other branches or tags.

我也看到过类似的问题,人们建议重组svn存储库.就此问题而言,这不在讨论之列.

I've seen similar questions and people have suggested restructuring the svn repository. This is off the table as far as this question is concerned.

推荐答案

我想出了一种从任意svn存储库结构中提取多个分支的方法.

I've figured out a way to pull in multiple branches from an arbitrary svn repository structure.

git svn init-b选项仅在所有分支都在存储库的子目录中(例如在标准布局中)分组在一起的情况下才起作用.如果所有分支(包括主干)并排在同一个文件夹中,则此操作将不会真正起作用.您可以通过从本质上在git存储库中创建多个树干"来从svn存储库中提取选定的分支.

The -b option for git svn init will only work if all branches are grouped together within a subdirectory in the repository, such as in the standard layout. If all branches, including the trunk, are side by side in the same folder, this won't really work. You can pull in selected branches from the svn repository by essentially creating multiple "trunks" int your git repository.

从问题中假设平面结构具有三个分支主干,featureX和featureY.

Assume the flat structure from the question with the three branches trunk, featureX, and featureY.

  1. 实例化您的git存储库.

  1. Instantiate your git repository.

mkdir myproject
cd myproject
git svn init url:to/svn/repo -T trunk

这将在.git/config文件中创建一个包含svn元数据的git存储库.

This will create a git repository with svn metadata in the .git/config file.

打开配置文件并检查svn元数据

Open the config file and examine the svn metadata

vim .git/config

您的配置文件将如下所示.

Your config file will look something like this.

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  autocrlf = false
[svn-remote "svn"]
  url = url:to/svn/repo
  fetch = trunk:refs/remotes/trunk

svn-remote标头定义了一个称为"svn"的引用,该引用指向您的svn存储库. fetch参数告诉g​​it-svn从svn存储库中提取新修订的位置.现在我们需要告诉git-svn我们感兴趣的另一个分支.

The svn-remote header defines a reference called "svn" pointing to your svn repository. The fetch parameter tells git-svn where to pull new revisions from within the svn repository. Now we need to tell git-svn about the other branch we're interested in.

复制svn-remote部分

复制配置文件的整个svn-remote部分,并将其粘贴到现有的配置文本下方.

Copy the entire svn-remote section of the config file and paste it below the existing config text.

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  autocrlf = false
[svn-remote "svn"]
  url = url:to/svn/repo
  fetch = trunk:refs/remotes/trunk
[svn-remote "svn"]
  url = url:to/svn/repo
  fetch = trunk:refs/remotes/trunk

  • 修改新的svn-remote部分

    更改svn-remote节标题的名称及其指向的分支的名称.

    Change the name of the svn-remote section header and the name of the branch that it points to.

    [core]
      repositoryformatversion = 0
      filemode = true
      bare = false
      logallrefupdates = true
      autocrlf = false
    [svn-remote "svn"]
      url = url:to/svn/repo
      fetch = trunk:refs/remotes/trunk
    [svn-remote "svn-featureX"]
      url = url:to/svn/repo
      fetch = featureX:refs/remotes/featureX
    

    现在git-svn将跟踪两个svn分支.您可以在带有[svn-remote]参数的任何git-svn命令中使用名称"svn"和"svn-featureX".您可以在任何以远程分支名称作为参数的git命令中使用名称"trunk"和"featureX".

    Now git-svn will track both svn branches. You can use the names "svn" and "svn-featureX" with any git-svn command that takes an [svn-remote] parameter. You can use the names "trunk" and "featureX" with any git command that takes a remote branch name as a parameter.

    此解决方案无法很好地扩展,并且与格式错误的svn存储库一起使用时可能有点麻烦.只要您只需要跟踪少数svn分支,就可以正常工作.如果您需要使用的svn分支数量过多,请认真考虑将svn存储库重组为标准布局.

    This solution won't scale well, and is a bit of a hack to work with a malformed svn repository. So long as you only need to track a handful of svn branches, this will work just fine. If the number of svn branches you need to work with becomes too large, take a serious look at restructuring your svn repository to the standard layout.

    这篇关于如何使用具有非标准svn回购布局的git-svn访问svn分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆