logo
Published on aidanf.net (http://www.aidanf.net)

Using git for offline commits to a subversion repository

By aidan
Created 2007-12-10 09:50

In my previous post about git [1] I mentioned that one of the nice things about git is it’s support of svn and cvs. I only mentioned it briefly but this is one of the features that keeps making people go “Wow, that’s cool!” when I explain it to them. So you can use git on a project which is centrally stored in svn or cvs or one where other team members are using svn or cvs. Here’s an example of using git with subversion.

First install git with svn support. For mac I use macports [2]. This command installs git and dependencies.

sudo port install git-core +svn

When I first tried running git-svn it gave an error about not finding some perl library. So to get git-svn to work I had to make sure it was using the macports perl rather than the system perl. I just replacing /usr/bin/perl with a link to /opt/local/bin/perl.

Next import your svn repository into a local git repository.

git-svn clone svn-repo-address

This creates an git repository in the current directory and imports the svn repository into it. This gives you the full commit history of the svn project. It also probably uses a lot less storage than your svn repository.

Change into the repository directory and use git log or git log --stat to see a list of your commits. Use git status to see current status of changes.

You can now make some changes locally and use git to manage them. Say I’m going on a flight and I won’t have internet access for the next 8 hours. I can work with my local git repository and commit each set of changes to this local repository.

git commit -a -m "yet another change"

I can also push these changes back to the central svn repository. Git will translate all my local commits these into a set of svn commits and commit them into the svn repository. So after my flight lands I can push back all the commits that I made while I was offline back to my projects central svn server. To do this start by running

git-svn rebase

This checks for changes in the remote repository since your last checkout and takes them into your repository in case other people have committed changes while you were offline.

git-svn dcommit

This commits all the changes in your local repository back to the remote subversion repository. And you’re done. All your changes are now back in the remote subversion repository.


Source URL:
http://www.aidanf.net/blog/2007/12/10/using-git-offline-commits-subversion-repository