Getting the subversion repository number into code

Two ways:

Embed $Id$ or $Revision$ within the code. Then set svn:keywords=”Id Revision” property on the file. This will give you the last modified revision of that source file. Good for smaller projects and scripts.

Alternatively, use a Makefile driven process and the command line tool svnversion. (Language specific – this should work for C/C++)

echo -n "#define VERSION 1.0.1-" > version.h
svnversion -n . >> version.h

Or some more complex build script with sed and version.h.in. Then just #include version.h

That will give you the repository version number, which will change with every commit / update, and is probably a more appropriate version number for most projects.

Note: I also used a human readable version string that I manually update. The example would give: Version: 1.0.1-r13445

~J

Leave a Comment