Svn in the git era without driving insane

hacksProgramming

If you, like me, are used to the beauty of git and create a branch for any single feature you would like to add to the master branch you are upset if you end up in a company that only uses svn as revision control system and they are not willing to make a switch anytime soon.

Some people, even dev managers, sometimes can’t understand how much more productive a good tool make employees. If you are used to merge the code or rebase with git you will find the merging tools of svn kinda obsolete. The fact that if somebody is doing a merge nobody else can commit to svn or everything may break is simply an insane idea for me.

If you are stuck in this kind of environment, you have a savior: it’s called git svn. I’ve been using it from more than one year now and I feel it great. The main concept is simple: git svn imports svn repositories into git ones. After this you can use them as normal git repositories. You can, for example, commit, rebase, rebase interactively, merge and then commit back to svn in the right branch. Git will figure out which is the right branch, but you can change it of course. To start with git svn just clone a svn repository with:


git svn clone -s svn://my_cool_server.com/my_cool_project

The -s will tell git to expect a standard format of svn, the one with a directory for trunk, branches and tags. If you are so unlucky to work with a not standard repo, you can use the -T -t and -b to specify the layout for trunktags and branches. This command will start fetching from revision #1 and will apply all the subsequent revisions. If you have a big repository (i’ve one with 50000 commits) you clearly don’t want to do that unless you don’t want your pc to spend days in fetching all reviews. You can tell git to only fetch the latest N revisions with :


git svn clone -s -rN:HEAD svn://my_cool_server/my_cool_project/

where N is a number.

After cloning, your new repo you can access your svn branches over remotes/BRANCH. This means that you can easily create a local branch that will track a svn branch with:


git checkout -t remotes/BRANCH

You can now do all commits, merges, rebase, interactive rebase you want, and even look at the svn patches and log with git log.

And finally, when you want to commit on the remoted tracked branch you simply do:


git svn dcommit

Sweet, isn’t it ?

Previous
Javascript regexps demystified
Next
Geany handbook

Leave a Reply

%d bloggers like this: