Previous Section  < Day Day Up >  Next Section

Recipe 18.2. Building a Simple Local RCS Repository

18.2.1 Problem

You're worried that someday you'll change some file, break something, and you'll forget how to undo the change. So you want a simple, local version control repository for tracking code changes, configuration files, scripts, and other documents for a single user. You don't need network access or support for multiple users—just something quick and easy to use for yourself.

18.2.2 Solution

Install RCS (Revision Control System) from RPMs, .debs, or sources. Then follow these steps to create your RCS repository.

First create a working directory, then create an RCS subdirectory:

$ mkdir projecthome

$ cd projecthome

$ mkdir RCS

Make sure you are in your working directory (projecthome) with some files to play with. This is how you check a file into the repository:

terri@workstation1:~/projecthome$ ci -u cupsd.conf

RCS/cupsd.conf,v  <--  cupsd.conf

enter description, terminated with single '.' or end of file:

NOTE: This is NOT the log message!

>> LAN printer server, for windows and linux, no samba

>> .

initial revision: 1.1

done

When you want to edit the file, check it out of the repository, then open it in your favorite text editor:

terri@workstation1:~/projecthome$ co -l cupsd.conf

RCS/cupsd.conf,v  -->  cupsd.conf

revision 1.1 (locked)

done

terri@workstation1:~/projecthome$ kate cupsd.conf &

When you're finished, close and save the file, then check it in just like above. Add a comment for the log detailing your changes:

$ ci -u  cupsd.conf

RCS/cupsd.conf,v  <--  cupsd.conf

new revision: 1.2; previous revision: 1.1

enter log message, terminated with single '.' or end of file:

>> added administrative controls to prevent users from making changes to the server

>> .

done

18.2.3 Discussion

In a simple version control repository like this, you have only two directories to keep track of. Your working directory is where the working copies of documents are kept. The RCS directory is the actual repository. The files in the repository are given a ,v suffix, like this:

$ ls RCS

cupsd.conf,v

The different revisions are tracked inside the file:

$ less cupsd.conf,v

head    1.3;

access;

symbols;

locks; strict;

comment @# @;

1.3

date    2004.06.15.03.33.46;    author terri;   state Exp;

branches;

next    1.2;

1.2

date    2004.06.13.30.47;    author terri;   state Exp;

branches;

next    1.1;

1.1

date    2004.06.12.03.27.01;    author terri;   state Exp;

branches;

next    ;

desc

@LAN printer server, for windows and linux, no samba

.....

Keep in mind that the files in your working directory are temporary versions. When a file has reached a state where you wish to preserve it, check it into the repository.

RCS's commands are mnemonic:


ci -u

Check in and unlock


co -l

Check out and lock

Using the -u flag on checkin preserves the copy in your working directory. The file in the working directory is set to read-only, which prevents accidents, and reminds you to check the file out of the repository for editing.

File locking means only one person at a time can check out and edit a file, so RCS is not suitable for a busy project with multiple users. However, it is perfect for small projects and single users, with the added advantage of being simple to learn.

18.2.4 See Also

    Previous Section  < Day Day Up >  Next Section