How To Add Revision Number, ID Automatically To Subversion Files in Two Simple Steps

By Angsuman Chakraborty, Gaea News Network
Wednesday, October 25, 2006

Revision number of a file is an important information. Two most common uses are in serialization and in making version specific database upgrades for an application. I am using it for the later. Here is a simple way how you can add revision number (Id, Date, Author and HeadURL) automatically to your source files.

First you need to add the keyword anchor at the desired location in the file. For example to get Revision information you must add $Rev$ or $Revision$ to your chosen location.

Note: The keywords are case sensitive.

Then you need to inform Subversion that these keyword(s) need to be substituted in your chosen file. For example if you have added the $Rev$ keyword to translator.php. Then you run propset command as follows:
svn propset svn:keywords “Revision” translator.php

You are done!
Now, after commit, your $Rev$ keyword will be automatically replaced with something like:

$Rev: 130 $

Note: The number will be automatically updated whenever anyone commits a new revision.

The list of keywords (from Subversion documentation) along with their alternatives are:

Date

This keyword describes the last time the file was known to have been changed in the repository, and looks something like $Date: 2002-07-22 21:42:37 -0700 (Mon, 22 Jul 2002) $. It may also be specified as LastChangedDate.

Revision

This keyword describes the last known revision in which this file changed in the repository, and looks something like $Revision: 144 $. It may also be specified as LastChangedRevision or Rev.

Author

This keyword describes the last known user to change this file in the repository, and looks something like $Author: harry $. It may also be specified as LastChangedBy.

HeadURL

This keyword describes the full URL to the latest version of the file in the repository, and looks something like $HeadURL: https://svn.collab.net/repos/trunk/README $. It may be abbreviated as URL.

Id

This keyword is a compressed combination of the other keywords. Its substitution looks something like $Id: calc.c 148 2002-07-28 21:30:43Z sally $, and is interpreted to mean that the file calc.c was last changed in revision 148 on the evening of July 28, 2002 by the user sally.

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :