I recently found myself working on a very large subversion (svn) repository. The repository (possibly) contains the company’s entire code base, spanning nearly 90,000 revisions. Even within the module I’m working on, there are over 300 branches.
Being a git convert, the first thought that occurred to me was to try git-svn, instead of moving back to svn. I love the ability to create multiple local feature branches. (I also prefer the way git merging works. But git-svn is restricted to the svn merge model).
For projects with many branches, it is recommended you clone one directory only. Otherwise, the resulting git repository will be many times larger than the original trunk.
git svn clone http://svn.mycompany.com/projectx/iteration123
Partial Cloning
However, I wanted to clone the trunk and a selection of branches. There are the options –trunk, –tags, –branches for svn repositories with non-standard layouts. Git-svn will also skip checking out paths specified with the option –ignore-paths.
After some experimentation, I found it easier to create an empty git repository, manually edit .git/config, and then fetch. Instead of using the command line options to clone.
git svn init http://svn.mycompany.com/projectx
Edit .git/config
[svn-remote "svn"]
url = http://svn.mycompany.com/projectx
fetch = trunk:refs/remotes/trunk
branches = branches/{iteration123}:refs/remotes/branches/*
The branches entry must contain a wildcard, or git-svn will complain with an error message along the lines of ‘glob needed’. I used the curly braces to fetch the branch iteration123 only. Multiple branches can be specified comma separated, like {iteration123,iteration124}.
I also restricted the fetch to recent revisions, by using the -r option
git svn fetch -r 80000:HEAD
Workflow
After the initial cloning hurdle, I found git-svn very straightforward to use.
At the start of each day, I merged changes from svn by using
git svn rebase
I committed changes to my local git repository with
git commit (-a)
Git-svn pushes each local commit as a separate commit to the remote svn. However, I committed very often and I really didn’t fancy polluting the svn log with lots of ‘reverting’, ‘trying x approach’. Therefore, I squashed all my commits for a scrum task into one commit before pushing the changes back to svn trunk.
git rebase -i branches/iteration123
git svn dcommit