Last Updated: 21 Nov 2020
Setting the $Id$ Tag in Subversion
CVS will automatically set an $Id$
tag in each file; it looks something like this:
$Id: test.php 110 2009-04-28 05:20:41Z dordal $
This is super-helpful for two reasons:
- it lets you know at a glance what revision of a file you're working with, and who last worked on it
- if you export your code (say as part of a deployment process), it lets others know what revision of a file they have
Subversion, by default, doesn't add these tags. However, you can configure it to set the tag when you checkin a file.
Note that this configuration has to be done client side; unfortunately you can't set this on the svn server for all clients. If you have multiple developers, you'll need to be pretty strict about making sure they all go through this procedure.
Configure subversion to automatically add the $Id: $ tag
First, update your ~/.subversion/config
with the following info:
[miscellany] enable-auto-props = yes [auto-props] *.php = svn:keywords=Id *.js = svn:keywords=Id
NOTE: You may want to add additional file types to the list above. As it stands, it will only set $Id: $ tags for *.php
and *.js
.
Set props on existing files
That configuration will automatically apply the svn:keywords
property (which sets the $Id$
tag) to all new files. But what about existing files? For these, you'll have to set the property manually. Go to the root of your source tree, and run this command:
find . \( -name "*.php" -o -name "*.js" \) -exec svn propset svn:keywords Id {} \;
find
will return a list of all .php
and .js
files, and then run svn propset
on them to set the appropriate svn:keywords
property. Now, all files have the property set, and will automatically set the $Id$
tag on checkin.
Add the $Id$ tag to each file
Finally, go through each file and add the prototype $Id$ tag. I like to do this in the comments at the header of each file, e.g.:
/*
* @author David Ordal, david -at- ordal.com
* @version $Id$
*
*/
When you checkin the file, you'll see it expand to:
/*
* @author David Ordal, david -at- ordal.com
* @version $Id: test.php 110 2009-04-28 05:20:41Z dordal $
*
*/
That's it!
Discussion
Nice one, thanks. I always forget exactly how to get this set up.
Thanks for this quick lesson, very helpful.
There's more tags to set than just the ID too. You have to set each one up in the ~/.subversion/config file, but here's the subversion guide to using them:
http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html
Thanks for the information. For the Windows users, the same config file would be found in %USERPROFILE%\Application Data\Subversion\config
That's really tihknnig out of the box. Thanks!
I was really cofnused, and this answered all my questions.
Great information!
Also ,I want to enable revisions logging in my file so that it look below snippet whenever I commit my code to SVN:
/*
Is it possible? Thanks in advance!