Using git-svn For Fun and Profit

Posted by Eric Stein - March 17, 2008 CE @ 09:27:01 UTC
For the last few weeks I've been using git-svn while developing offline. It's optimal for me because SVN supports all my online coding flow & I run an SVN server already.

Cloning an SVN Repository


Given git's reputation as a bit of a challenge to use, it's surprisingly easy to get started with git-svn.
~ $ git-svn clone svn://svn.example.com/project
Initialized empty Git repository in .git/
        A       FILE
r1 = 30c7f86823da99538fae8afca5ca46d3d43c32f7 (git-svn)
Checked out HEAD:
  svn://svn.example.com/project r1

Using Your Git Repository Offline


This will check out the entire history of your repository into a local git repository. Now, I know that git has a reputation as being large, scary, and complicated, so I'll include a quick primer on how to use git for everday SCM tasks.

Adding Files

~ $ cd project
~/project $ touch newfile
~/project $ git add newfile
~/project $ git commit -a -m "adding a new file"
Created commit 4312745: adding a new file
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 newfile

Quite easy, really. A little more verbose than svn, but understandable.

Modifying Files

~/project $ cat >> newfile
added a line to the new file
~/project $ git commit -a -m "wrote some data"
Created commit 58efa1c: wrote some data
1 files changed, 1 insertions(+), 0 deletions(-)

That's along the same lines. Nothing that hard!

But I'm Online Now...


So you're back from your sojourn in the desert now, and you've been productive. Now it's time to merge your changes into the SVN repository. But first, we need to do the equivalent to svn up before committing:
~/project $ git-svn rebase
Current branch master is up to date.

Looks like it's all clear. Time to actually commit those changes:
~/project $ git-svn dcommit
Committing to svn://svn.example.com/project ...
        A       newfile
Committed r2
        A       newfile
r2 = 4f50219cbf276ed6cf6a94641e1bbce94c2f44a6 (git-svn)
No changes between current HEAD and refs/remotes/git-svn
Resetting to the latest refs/remotes/git-svn
newfile: needs update
        M       newfile
Committed r3
        M       newfile
r3 = 518ba784aa23241e74297fd62406591e8d433922 (git-svn)
No changes between current HEAD and refs/remotes/git-svn
Resetting to the latest refs/remotes/git-svn

Now all your changes are in the main SVN repository as individual commits. Now put git-svn into your toolbox to end the days of shuffling files about by hand, worried that you'll break something.
Last Edited July 29, 2008 CE @ 03:45:31 UTC

Comments

There are no comments yet.

Post a Comment

Name
Email (not published, I won't spam you)
URL (optional)
Title
Comment
square root of 49?
Worth Saying
Valid XHTML, CSS, RSS | 1ms | Copyright 2004-2024 Eric Stein