Git+SVN: Script To Do “Svn Up” And “Git Commit” With Svn Revision Number

I’ve been using Git+SVN for a while now, and I really like what it does for me. What I don’t like is the constant repetition of the same command to update from svn into my local git branch, over and over and over again. So, I wrote a little batch file to do my svn update and my git commit. I committed it to our repository so that I wouldn’t lose it when branching, merging, etc. and one of my coworkers asked if it was populating any useful info into the git commit message, like the svn revision #. At the time it was only committing with a “svn up” message, but it was easy to add other detail.

Since I run in a bash shell most of the time (the Git Bash shell… MingW32), I decided to take advantage of the bash commands like grep and piping, etc, to get the svn info that I wanted into my commit message. I wanted to get the svn revision number. This can be obtained by running “svn info”:


the “Revision: 30165” line is what I’m looking, so a simple command like “svn info | grep Revision” should do the trick:


Then, with a little help from Tim Ottinger, I got the command line i needed to insert this info into my git commit message: git commit –m “$(svn info | grep “Revision”*)”

The resulting batch file has these commands in it:

   1: svn up

   2: git add -A

   3: git commit -m "svn up to $(svn info | grep "Revision"*)"

And it looks like this when I run it, proving a nice log entry for me:


About Derick Bailey

Derick Bailey is an entrepreneur, problem solver (and creator? :P ), software developer, screecaster, writer, blogger, speaker and technology leader in central Texas (north of Austin). He runs - the amazingly awesome podcast audio hosting service that everyone should be using, and where he throws down the JavaScript gauntlets to get you up to speed. He has been a professional software developer since the late 90's, and has been writing code since the late 80's. Find me on twitter: @derickbailey, @mutedsolutions, @backbonejsclass Find me on the web: SignalLeaf, WatchMeCode, Kendo UI blog, MarionetteJS, My Github profile, On Google+.
This entry was posted in Git, Source Control, Subversion. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • enriquein

    Awesome. You’re on a roll with the git posts