BSD Tricks: Introductory Revision Control
Pages: 1, 2
Each time you check in a file, it's assigned a revision number (in the above example, 1.2). You can use the revision number to check out any previous version of the file. If you're, say, trying to track a bug that's just appeared in your program, you can check out earlier versions of your code and see if they also exhibit the bug. You can do this with
co using the
-r flag. For example, to check out an earlier version of
/etc/rc.conf you would do:
co -r1.1 rc.confRCS/rc.conf,v --> rc.conf revision 1.1 done
Always check files in when you've finished editing them, or if you're leaving for some reason. If another user needs to edit a file when you're gone, they'll have to break your lock. Any changes you make since locking the file will be lost.
rcs -u to break a lock. RCS will ask you for a message about why you're breaking the lock, which will be mailed to the lock holder. Be careful using this in shared files; if someone is really editing a file when you forcefully break the lock, they'll be justifably upset. If they've gone home for the day, that's another thing.
RCS provides a variety of other functions. My favorites are
rcsdiff, and the ident strings. The
rlog command shows you the log messages for the file, for example:
RCS file: /etc/RCS/rc.conf,v
Working file: /etc/rc.conf
keyword substitution: kv
total revisions: 4; selected revisions: 4
date: 2000/09/08 17:45:29; author: mwlucas; state: Exp; lines: +2 -0
date: 2000/09/07 19:05:30; author: mwlucas; state: Exp; lines: +1 -1
*** empty log message ***
date: 2000/09/05 16:09:47; author: mwlucas; state: Exp; lines: +1 -1
date: 2000/09/02 14:53:43; author: mwlucas; state: Exp;
All sorts of useful information appears here; the date each check-in was made, the author of the change, the entry's state (which we don't worry about here, see ci(1)), and the number of lines changed. Here we see I didn't bother leaving a log message in revision 1.3. To see what changed, use
rcsdiff command takes three arguments: two revision numbers and a file name.
rcsdiff -r1.2 -r1.3 /etc/rc.conf
RCS file: /etc/RCS/rc.conf,v
retrieving revision 1.2
retrieving revision 1.3
diff -r1.2 -r1.3
Apparently I turned
inetd on. This would have been useful to know in a production system, especially one administered by several people.
You can use
rcsdiff between arbitrary revision numbers, allowing you to view the total diffs made between any two entries.
Lastly, ident strings can be embedded in files under RCS protection. They're used to put human-readable RCS information in the file. Each string is in the form
$string$. For example, the RCS ident string
$Id$ puts information about the last change in the file. When I put
/etc/rc.conf, it appears as:
#$Id: rc.conf,v 1.5 2000/10/05 18:29:49 mwlucas Exp mwlucas $
The pound sign is included so that
/etc/rc won't try to run the line. You can use whatever comment is appropriate for the type of file.
For a complete list of ident strings, see ident(1).
RCS is a terribly powerful tool. For more details, check ci(1), co(1), and rcs(1). This should get you started, however. Careful revision control can save you hours of later debugging and troubleshooting.
Read more Big Scary Daemons columns.
Discuss this article in the Operating Systems Forum.
Return to the BSD DevCenter.