Using git for offline commits to a subversion repository

In my previous post about git 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. 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.

I keep getting this error on the port install:

Error: Target org.macports.activate returned: Image error: /opt/local/lib/perl5/5.8.8/darwin-2level/perllocal.pod already exists and does not belong to a registered port. Unable to activate port git-core.
Error: Status 1 encountered during processing.

Is your ports collection up to date? Try running sudo port selfupdate first.

You can also install git from source.

I updated to macports 1.6 (from 1.5.2). Still the same error.

I'm having the same problem, and I don't know how to fix it :-(

Nice post.

I still haven't had the opportunity to fully switch over to using git.

So far, this is one of my favorite ways to use it though. You get all the local commits/branching from git, but still having a centralized subversion server.

I have never used git, but I am now very curious to use it. I am always online and I do my commit online, but what you mentioned worth giving it a shot.

Thanks

Regards,
Brian

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.