Author: Mayur Prakash Srivastava
Revision Control System
The tool that we use to keep track of changes to files, and to reverse those changes if necessary, is called the Revision Control System, or RCS for short.
-
The RCS Subdirectory
The information (revision) about each file is kept in an RCS subdirectory.
Create a subdirectory RCS before using RCS commands. (Optional but recommended).
-
The rlog command
The rlog command displays the change history of a file and its current lock status. rlog gets the necessary information from the RCS/filename,v file corresponding to the file specified by the user. For example:
bash% rlog testfile
RCS file: RCS/testfile,v
Working file: testfile
head: 1.1
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
original version.
----------------------------
revision 1.1
date: 2002/06/26 14:39:08; author: mayur; state: Exp;
Initial revision
=============================================================================
-
The rcsdiff command
You can find the exact difference between one revision of a file and another by using the rcsdiff command.
For example:
bash% rcsdiff -r1.1 testfile
===================================================================
RCS file: RCS/testfile,v
retrieving revision 1.1
diff -r1.1 testfile
1a2
> This line has been added later in next version.
Here the rcsdiff command was used to find the difference between revision 1.1 (selected by the -r1.1
option) and the current revision (by default) of file testfile . The
rcsdiff command created a temporary file containing revision 1.1 of the specified file, and invoked the Unix
diff utility to compare the temporary file to the current revision.
-
The co command
Before you can change a file which is registered with RCS, you must get control of it with the co (CheckOut)
command. Most of the time, a file which is registered with RCS has read-only permissions, and is not locked.
For example:
bash% ls -l testfile
-r--r--r-- 1 mayur mayur 64 Jun 26 20:12 testfile
bash% rlog testfile
RCS file: RCS/testfile,v
Working file: testfile
head: 1.2
branch:
locks: strict
access list:
......
Run the co command, specifying the -l option to lock the file:
bash% co -l testfile
RCS/testfile,v --> testfile
revision 1.2 (locked)
done
This locks the file and makes it writeable:
bash% ls -l testfile
-rw-r--r-- 1 mayur mayur 64 Jun 26 20:18 testfile
bash% rlog testfile
RCS file: RCS/testfile,v
Working file: testfile
head: 1.2
branch:
locks: strict
mayur: 1.2
access list:
....
You can now edit the file with your favorite editor. While you have the file locked, anyone who tries to get control
of it with co will receive a warning message:
bash% co -l testfile
RCS/mime.types,v -> testfile
revision 1.2 (locked)
writable testfile exists; remove it? [ny](n): n
co: checkout aborted
-
The ci command
When you have finished making changes to a file, and have tested the results enough to give you reasonable
confidence, it is time to give control of the file back to RCS. You do this with the ci (CheckIn) command.
For example:
bash% ci -u testfile
RCS/testfile,v <-- testfile
new revision: 1.3; previous revision: 1.2
enter log message, terminated with single '.' or end of file:
>> Latest version.
>> .
done
Enter the ci command with the -u option to unlock the file you changed. Then enter one or more lines
explaining the change you made, finishing with CTRL-D. The explanation need not detail exactly what you
changed, since that can be obtained with rcsdiff. The explanation should instead summarize the purpose of
the change, and put it into larger context.
-
The rcs command
The rcs command can be used to directly change the stored revision history of a file. rcs can be used to
permanently throw away an unsuccessful revision, or change the description of a stored revision. Details are on
the rcs man page.
-
Using RCS with emacs
If you use the emacs editor to edit a file registered with RCS, you can give emacs commands to perform the
necessary co -l and ci -u operations and thus avoid using separate shell commands.
The commands you give to emacs are as follows:
- 1.Type C-x C-f filename to find the file you want to edit. emacs will give you the message:
Note: File is write protected
to let you know that the file is not checked out.
-
2.Within the same buffer, type C-x C-q to check out and lock this file. emacs will give you the message:
Checking out filename...done
-
3.Make your edits to the file.
-
4.Type C-x C-q again to check the file back in. emacs will open a second window, *VC-log* .
-
5.Type your description of the changes you made to the file into the *VC-log* window.
-
6.Type C-c C-c in the *VC-log* window to check the file in and unlock it.
-
FAQs
Q1. How Can I Tell Whether Somebody Changed A File Without Informing RCS?
Since RCS is not a coercive system, it's possible for somebody to make a change to a file without informing RCS of the change.
NB: Many programs and software installation tools change configuration files without informing RCS of the change. For example, if you install one of the GNU utilities, the install procedure will probably update file /usr/local/info/dir regardless of this file's status in RCS. You can discover whether such a change has been made by using rcsdiff to compare the present state of the file
with the last revision stored in RCS.
For example, to tell whether /opt/apache/conf/httpd.conf has been changed from the stored version:
bash% rcsdiff /opt/apache/conf/httpd.conf
===================================================================
RCS file: /opt/apache/conf/RCS/httpd.conf,v
retrieving revision 1.5
diff -r1.5 /opt/apache/conf/httpd.conf
192c192
< CookieTracking on
--
> CookieTracking off
We can see that CookieTracking has been changed from on to off. But:
bash% rlog /opt/apache/conf/httpd.conf
RCS file: /opt/apache/conf/RCS/httpd.conf,v
Working file: /opt/apache/conf/httpd.conf
head: 1.5
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 5; selected revisions: 5
description:
...
shows that there is no lock on the file, so somebody has made this change without informing RCS.
Q2. Somebody Changed A File Without Using RCS. How Do I Get The Changes Into RCS Without Losing Them?
First you need to inform RCS that the file is being changed, then you need to submit the changes. You do this with a sequence of two RCS commands.
For example, to preserve a change to /opt/apache/conf/httpd.conf, which is owned by root, do:
bash% su
Password:
# cd /opt/apache/conf
# rcs -l httpd.conf
# ci -u httpd.conf
The command rcs -l httpd.conf locks the file in RCS, which in other words accomplishes what would have been done if the file had been checked out properly. Then the command ci -u httpd.conf submits the changes to RCS.
For more information goto this page.
Author: Mayur Prakash Srivastava