How do I access svn branches using git-svn with a non-standard svn repo layout?

拈花ヽ惹草 提交于 2019-12-10 16:38:40

问题


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

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.

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.

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.


回答1:


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

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.

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

  1. Instantiate your git repository.

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

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

  2. 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
    

    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.

  3. Duplicate the svn-remote section

    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
    
  4. Modify the new svn-remote section

    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
    

    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.

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.




回答2:


As this article illustrates, you can write rules for running an importer tool like svn2git
(you have less complete version of svn2git here)

See those examples for rules that you could rewrite in order to match those flat SVN directories/branches and declare them as Git branches.



来源:https://stackoverflow.com/questions/3681080/how-do-i-access-svn-branches-using-git-svn-with-a-non-standard-svn-repo-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!