Getting the Revision Number of your Subversion Working Copy

July 20, 2006 - 2 minute read -

I was asked today "How do I find out the revision number of my Subversion directory?" and I didn't know the answer. The good news is there is an easy answer:

svnversion . 

From the

svnversion help

The version number will be a single number if the working copy is single revision, unmodified, not switched and with an URL that matches the TRAIL_URL argument. If the working copy is unusual the version number will be more complex:

This command takes a little while to run, because it runs against the remote repository as well. It gives more detailed results also such as whether or not you have local modifications or if the repository has been changed since your last update. These details can be interesting in certain cases. But sometimes all you want to know is what revision you currently have checked out...

If all you want to do is check on the current revision of your local working copy you can use some Unix magic to do that.

grep revision .svn/entries |  awk -F\" '{print $2}'

Redirect this output to a file or use it as an argument to a build script and you can have the revision number put into your application.

ant -Drevision=grep revision .svn/entries | awk -F\" '{print $2}'
(notice the backticks ` and this needs to be on one line)

A little Unix scripting and voila!

(Thanks to Ross Greinke for this little snippet)

[ad name="image-banner"]