How to use Git SVN to track branches only?
I'm working with a very large Subversion repository that has a pretty messy history. It has a standard directory layout but for one reason of another I can't clone it using git svn clone
. After leaving it running for ~2 days it seems to get into an infinite loop so I've abandoned cloning the full repository.
The repository has a main development branch /branchs/dev and a number of feature branches off that branch. What I'd like to do is only track the dev branch and feature branches, with git's master branch tracking dev and each feature branch a regular git remote branch.
Up to now I've been creating separate Git repositories for the dev branch and each feature branch. I only fetch the the last n commits from each branch because I didn't see a need to fetch them all (plus the 'dev' branch 开发者_运维技巧doesn't come directly off 'trunk 'even though in theory it should). Here's what I used...
$ git svn init <full svn branch url> <dir name>
$ cd <dir name>
$ git svn fetch -r <start rev>:HEAD (where <start rev> is either the last or some recent commit on the branch)
Using this method allows each branch to operate well in isolation but it means I can't use git to merge from dev down to feature branches and vice versa.
How can I use Git to track the 'dev' and feature branches only within one repository?
I haven't had a chance to try this, but git svn clone
lets you specify the trunk dir with the --trunk=
option and the branches with --branches=
, so you should be able to do something like
git svn clone --trunk=branches/dev --branches=branches/dev/features http://svn.foo.com/svn/project
or however your setup is. The git-svn man page also states that you can use multiple --branches
tags, in case not all of your branches fall under one directory.
Edit: To clarify, this will just check out whatever you specify as trunk and make that your master branch in the git repository. If you want to work with one of the other feature branches, you can do
git checkout -b local/branch_name remote_branch_name
to get that branch. The --branches=
option to git svn clone
just tells git where to look for branches when you do a command like the above.
精彩评论