Using git-svn for svn disaster recovery

Real Life dictates that I use SVN servers outside my control, and that makes me nervous that they might go down or otherwise become unavailable near an important deadline. Here is how to cope with that thanks to the wonders of git and git-svn. Note: Experienced git users may balk at this. I do too now that I have some git experience. However, it is intended to help inexperienced SVN users cope. Maybe nothing can actually accomplish that goal? /rant

  • Assumes no-password ssh to localhost is possible.
  • Otherwise, several commands will prompt for a password

Demonstrate the basic operation of the SVN repo. Note: In the scenario of concern, localhost is replaced by some other system outside one’s administrative control

svnadmin create /tmp/svnrepo
svn checkout svn+ssh://localhost/tmp/svnrepo /tmp/svncheckout
cd /tmp/svncheckout
echo "hello" > test.txt
svn add test.txt
svn ci -m "informative commit message"

Demonstrate git-svn

git svn clone svn+ssh://localhost/tmp/svnrepo /tmp/gitsvnclone
cd /tmp/gitsvnclone
echo "more stuff" >> test.txt
git add test.txt
git commit -m "added some more stuff"
git svn dcommit

Demonstrate disaster. The SVN server has gone down. However, we (let’s call ourself “Alice”) have a local git repository with the full history of the SVN server. Our basic disaster recovery is to adopt the convention that this local git repository is the “new official server”. Another team member (“Bob”) can readily clone our own git repository and work within it:

git clone git+ssh://localhost/tmp/gitsvnclone aregulargitclone

Here is what NOT TO DO…

cd /path/to/aregulargitclone
echo "more stuff" >> test.txt
git add test.txt
git commit -m "added some more stuff"
git push

…because you will get the following:

remote: error: refusing to update checked out branch: refs/heads/master

This is saying that things can get out of sync in the “new official server” git repository. What Bob needs to do is make sure his work is within a git “branch”. Below is what Bob should do. For more
information about branches see, e.g., http://stackoverflow.com/questions/2670680/git-basic-workflow

cd /path/to/aregulargitclone

Now create a new branch with a unique name:
git checkout -b bobsedits master
…and then proceed to do work as usual.

echo "more stuff" >> test.txt
git add test.txt
git commit -m "added some more stuff"
git push

This will work fine. Now there is a branch called “bobsedits” back in Alice’s git repository. Alice can merge the changes:

git checkout master
git merge bobsedits

Basically what has happened is that “master” has become the anointed stack of changesets, and each individual editor / developer must make their edits on a branch. Once the SVN server comes back online, Alice can make sure everybody’s branches are merged into master, and she can the ‘git svn dcommit’ them back to the server.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s