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.
I've figured out a way to pull in multiple branches from an arbitrary svn repository structure.
The
-b
option forgit 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.
Instantiate your git repository.
This will create a git repository with svn metadata in the
.git/config
file.Open the config file and examine the svn metadata
Your config file will look something like this.
The
svn-remote
header defines a reference called "svn" pointing to your svn repository. Thefetch
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.Duplicate the
svn-remote
sectionCopy the entire
svn-remote
section of the config file and paste it below the existing config text.Modify the new
svn-remote
sectionChange the name of the
svn-remote
section header and the name of the branch that it points to.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.
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.