Home > Articles > Programming

  • Print
  • + Share This
From the author of

Simple Version Control Using RCS

Although many different version control systems are out there, the ones I use the most often are RCS for my personal projects and CVS for commercial projects (normally with the WinCVS front end). Although CVS, the Concurrent Versions System, is really nice, I prefer the simpler command-line RCS tool for my solo projects. The main difference between the two is that RCS uses an exclusive checkout model, whereas CVS allows multiple people to work on a file at the same time, seamlessly merging the edits when the file is checked in. Having used both on large projects, I prefer CVS when working in a team because it allows many people to work simultaneously, but I find the extra complexity of CVS is not worthwhile for solo projects.

RCS itself is available from http://ftp.cvshome.org/rcs/; you need to download both diff27nt.zip and rcs57nt.zip. To install RCS, unzip the files into a convenient directory. (You'll probably want to make sure that this directory is part of your system PATH.) Once you've unzipped the files, enter the command rcs -V to confirm that everything is working okay (it should report RCS version 5.7).

Using RCS is very simple. To set it up, create an RCS directory inside your project directory, and then you can start to use RCS.

To check in a file, use the ci (check in) command. The first time through, RCS will ask you for a description of the file. The file is then removed from the project directory and saved away into the RCS directory.

D:\InformIT>ci CircularCounter.rb
RCS/CircularCounter.rb,v <-- CircularCounter.rb
enter description, terminated with single '.' or end of file:
NOTE: This is NOT the log message!
>> Sample file for the Ruby for the OO Nuby article
>> .
initial revision: 1.1
done

To check out the file so that you can just use it, use the co (check out) command. If you want to be able to edit the file, use co -l as the command. (The -l means to lock the file. RCS gives you an exclusive, writeable copy of the file that you can modify and check back in.)

D:\InformIT>co Odometer.rb
RCS/Odometer.rb,v --> Odometer.rb
revision 1.1
done

D:\InformIT>co -l Odometer.rb
RCS/Odometer.rb,v --> Odometer.rb
revision 1.1 (locked)
done

After you have updated the file, check it back into version control with the ci command, this time with a log message stating what you changed:

D:\InformIT>ci Odometer.rb
RCS/Odometer.rb,v <-- Odometer.rb
new revision: 1.2; previous revision: 1.1
enter log message, terminated with single '.' or end of file:
>> Added some comments
>> .
done

Make your comments informative, because they'll help you understand how the file has been changed when looking through the revision history.

D:\InformIT>rlog -zLT CircularCounter.rb

RCS file: RCS/CircularCounter.rb,v
Working file: CircularCounter.rb
head: 1.5
branch:
locks: strict
    pete: 1.5
access list:
symbolic names:
    RubyNuby: 1.2
    TestDriven: 1.5
keyword substitution: kv
total revisions: 5;   selected revisions: 5
description:
Sample counter class for Ruby for the OO Nuby article
----------------------------
revision 1.5  locked by: pete;
date: 2002-03-07 17:39:43-07; author: pete; state: Exp; lines: +4 -1
Deliberate mistake fixed, minimal decrement added
----------------------------

The symbolic names in the revision history above are the key to getting a coherent set of files out of a directory. They're added using this command:

rcs -Nlabel:version filename

If the version is omitted, RCS defaults to the highest version:

rcs -NRubyNuby:1.2 CircularCounter.rb
rcs -NTestDriven: CircularCounter.rb

Once these labels are in place, it's easy to grab a related set of files from RCS using the command co -rlabel, which will check out all files with the specified label. (RCS will warn for all files that don't have the right label.)

D:\InformIT>co -rTestDriven RCS\*.rb,v
RCS\CircularCounter.rb,v --> CircularCounter.rb
revision 1.5
done
RCS\Odometer.rb,v --> Odometer.rb
revision 1.2
done
RCS\OdometerTest.rb,v --> OdometerTest.rb
co: RCS\OdometerTest.rb,v: Symbolic name ´TestDriven' is undefined.

The last bit of RCS that's very useful to know is the rcsdiff command, which lets you know what has changed between two versions. It compares the currently checked out file against the revision version you specify, 1.3 in this case (to make it more interesting, I first checked out the RubyNuby version):

D:\InformIT>co -rRubyNuby CircularCounter.rb
RCS/CircularCounter.rb,v --> CircularCounter.rb
revision 1.2
done
D:\InformIt>rcsdiff -r1.3 CircularCounter.rb
===========================================================
RCS file: RCS/CircularCounter.rb,v
retrieving revision 1.3
diff -r1.3 CircularCounter.rb
13c13
<   if (value > @limit)
---
>   if (value >= @limit)

And there you have it—a very simple, easy-to-use command-line version control system with just five commands:

  • ci Odometer.rb

  • co -rversion Odometer.rb or co -rversion -l Odometer.rb to edit the file

  • rcs -NRubyNuby:1.2 Odometer.rb

  • rcsdiff -r1.3 Odometer.rb

  • rlog Odometer.rb

  • + Share This
  • 🔖 Save To Your Account