Thursday, May 12, 2011

Using GIT as SubVersion (SVN) client

Install git-svn in Ubuntu

All git-* commands are implemented in Ubuntu with the git command: 'git-svn' is in Ubuntu 'git svn', notice the space.

Checkout

Do a checkout from SVN with
git svn clone -s -r [revision] [SVN URL] [new directory]
The [SVN URL] is the root of your SVN repository, the remote directory that contains your trunk, tags and branches subdirectories. The [revision] is the SVN revision number from which you want to retrieve history from. You may want to limit the history, because it takes time to retrieve all of the history from SVN. Example:
git svn clone -s -r 198 https://nextaction.googlecode.com/svn nextaction

Update from SVN

To update your local files from SVN, execute:
git svn rebase
If the update refuses to pull the changes from SVN and displays a message with "needs update", you probably made changes that you have not commited yet. Apparently, you must commit your changes locally first

Commit to GIT

When you make changes to your local files, you can commit them with:
git commit -a -m "Commit message"

Commit to SVN

This will only commit changes to your local GIT repository, to commit (or "push" in the GIT jargon) to SVN, use:
git svn dcommit