from subversion to git
Recently I’ve been playing with git and I found it fascinating!, for those that still don’t know what it is, git is a really fast distributed revision control system (wikipedia). Now the problem is how to switch from subversion to git, fortunately git-svn helps a lot and we can play with git and subversion in many ways. Let’s talk about them from the easiest to the not-so-easy way. I’m supposing here that you want to move from a centralized subversion to a git repository that probably will be online on a server.
Complete migration from subversion to git
This is for those that want to throw subversion away completely, for some reason this is the easiest way to switch. First what you would do on the server:
# first clone the repository from subversion
# if you can use file:// it will be faster,
# otherwise use http://your-project-url.com/svn/MySuperProject
[server]$ git svn clone -s file:///home/pplux/.../svn/MySuperProject tmp
# clone to a bare new git repository (with no track of subversion)
[server]$ git clone --bare file://`pwd`/tmp MySuperProject
# remove the old git repo from subversion, no longer needed
[server]$ rm -rf tmp/
# update server info, for "dumb" servers this is needed
[server]$ cd MySuperProject/
[server]$ git --bare update-server-info
Now clients can simple clone your repository and start working:
# use this for normal-read-only, or maybe you could use ssh://
# if you plan to upload data.
[client] $ git clone http://your-server-url.com/git/MySuperProject
Mirroring the subversion repository and keep subversion
Here we want to keep the subversion repository like the main reference of the project, but let people (or ourselves) use git for development. The reason to mirror the subversion is just a matter of speed, it is much faster to clone an existing git repository than cloning from subversion each time.
Here we will need to do a bit more of work, but it’s a much smoother way to migrate from subversion to git. First what we need to do on the server:
# Create and initialize a bare git repository
[server]$ mkdir MySuperProject[server]$ cd MySuperProject/
[server]$ git --bare init
Initialized empty Git repository in /home/pplux/.../MySuperProject/
# set svn project to import
[server]$ git --bare svn init -s http://your-server-url.com/svn/MySuperProject
# fetch svn data (sloooow)
[server]$ git --bare svn fetch --all
A src/CMakeLists.txt
A CMakeLists.txt
W: +empty_dir: trunk/include
...
# auxiliary files to help "dumb" servers
[server]$ git --bare update-server-info
Now the client, here we will do much more work than before to setup both the origin from the git mirror and the subversion config to commit there future changes.
# Create and initialize our copy of the git repository
[client] $ mkdir MySuperProject
[client] $ cd MySuperProject/
[client] $ git init
Initialized empty Git repository in /Users/pplux/projects/MySuperProject/.git/
# setup the server as the initial origin of data
[client] $ git remote add origin http://your-server-url.com/git/MySuperProject
# also tell git to fecth data from the remote origin(that case svn)
[client] $ git config --add remote.origin.fetch '+refs/remotes/*:refs/remotes/*'
# fetch data from the git mirror(takes a bit)
[client] $ git fetch
got 2c68737541f19685f667f601a502447425d1fcfe
walk 2c68737541f19685f667f601a502447425d1fcfe
got d4916373650b9bb636c0284dd501e6c7bfa8e304
got 13af9568120f8e7771bd386d9b7dadf69f1181cb
...
# setup the original subversion as
[client] $ git svn -s init http://your-server-url.com/svn/MySuperProject
# rebuild data...
[client] $ git svn fetch
Rebuilding .git/svn/trunk/.rev_map.1a3bf6a2-ba3d-0410-9263-a3f888f14dcd ...
r1 = 126490373bfbc2a770d762398b67fffeef73bead
r2 = a2288725c8c68ef426b97cf2b28a9135a34734d3
r3 = 4158b92a5c68489bb6ff2b4f4567cf8f830d7282
# to start working create a master that will track "trunk"
[client] $ git checkout -b master -t trunk
Reasons for switching to git
The post ends here you can safely stop reading now, but if you ask me, there are some good reasons to switch to git:
- it’s faster, not only faster when doing actual SCM work, it allows you to develop faster, no need to wait while the commit is transmitted to the server, you can work offline wherever you are…
- it works well with subversion, you can use it even if the main project never moves from a subversion repository or you are the only one using git while everybody else is using subversion
- you don’t need to develop a full feature before a commit, you can work on your own doing commits often without worrying about anybody else.
- git is meant to work on branches, this is a different approach from the normal subversion use, with git you are supposed to work on branches, and it’s great! I like to develop different «features» on different branches, I can switch the branch, do several things at the same time… and so on.
- you have the whole history, not just the last commit.
- it’s secure, you don’t need several people to share the same repository, git «default» model works in a different way where each person has its own public git. But, everything in git is hashed, even branches, so you can easily check if your private git has the same things as the remote git (that’s difficult to achieve with subversion)
- it’s like vim vs notepad! I like git because is fun, it can do many many things, and it’s always good to have something new to play with.
- if CVS was for dinosaurs when you started using SVN, now SVN is for the Neanderthals… so start using git!
- You don’t have to be a ruby developer to use git! git is another SCM… not the cool tool just for cool ruby developers… come on.
- Because Linus Torvalds made it:
- … well, maybe Linus is not a good reason to use it… I don’t fancy calling people ugly and idiot, anyway git is great.
And big thanks to slack for pointing me out git, if he says something is good stuff… believe him 🙂
Other good links about what we’ve talked here:
http://www.gnome.org/~federico/news-2008-11.html#27
http://markmcb.com/tag/workflow/
http://utsl.gen.nz/talks/git-svn/intro.html#howto-track-rebuildmeta
http://www.viget.com/extend/effectively-using-git-with-subversion/
http://techbase.kde.org/Development/Tutorials/Git#Interfacing_KDE.27s_SVN_repository_with_git-svn
http://live.gnome.org/GitForGnomeDevelopers
http://tsunanet.blogspot.com/2007/07/learning-git-svn-in-5min.html
http://blogs.gnome.org/johncarr/2008/06/21/git-mirrorgnomeorg/
http://markmcb.com/2008/09/17/migrating-a-subversion-svn-project-and-server-to-git/
I’ve tried to switch to git a couple of times, but there are still some problems that prevent me from doing it, which are:
– Dreamhost lacks git support; maybe you can do it manually, but there’s no fancy graphical setup.
– Lack of support from some applications: TextMate, Xcode, …
– Subversion is already installed in Mac OS X, but you have to install git manually.
– A good Windows client (such as TortoiseSVN), albeit I rarely use Windows these days.
– Linus Torvalds made it 😉
When it’s more mature it’ll beat subversion without a doubt, but right now I think it’s not yet ready for prime time.
Hi JoseMa,
Yeah, there is no official support on Dreamhost, but actually git doesn’t require any special apache module to work, you can publish a repository using plain http. And fortunately, git is installed, so only a «git –bare init» is enough to setup your repo 🙂
About the other reasons, you are right, probably the most difficult problem to solve will be the tortoise-like interface, git is much more complex so I can barely imagine how it could be done. I can believe there is no TextMate support given the number of Ruby & ROR developers out there using git… check it twice 🙂
For your information, Linus Torvalds made it, but currently he doesn’t maintain it, probably Hamano is nicer than Linus 🙂
That’s interesting, PpLuX 😀 , I thought git wasn’t installed in Dreamhost, though I must confess I didn’t bother checking. I might give it another try.
And yes, there is a TextMate bundle, which can be found here: http://gitorious.org/projects/git-tmbundle
Another reason I’m not using it yet is that it seems a bit harder than svn to use; I tried to make some branches and merge them but I had some problems with that, I don’t remember which right now, but if I encounter them again I’ll post my difficulties here.
And of course git isn’t as extended yet as svn, but I want to give git-svn a try.
It’s a relief knowing that Linus no longer mantains the project 😀
What about Mercurial? do you know how it compares to Git?
About Mercurial I know nothing at all. Just that even Linus see it as a good candidate for a distributed control system and that it’s mostly implemented in Python. They look pretty similar with focus on the same very issues, so probably you’ll be fine with any of them.
… Maybe is a bit slower than its C competitor… but, that’s just a guess.
Mmm, looks pretty interesting:
– GUI client for Windows, Linux and Mac: TortoiseHG http://tortoisehg.sourceforge.net/
– Bundle for TextMate which is even listed in the GetBundles Bundle
– Similar features to Git
BUT, it isn’t installed in Dreamhost, so you must follow this (http://wiki.dreamhost.com/Mercurial) instructions
very good……