Revision Control System

Linux RCS Revision Control System

RCS - Revision Control System


RCS is a system designed for controlling multiple versions of files. RCS controls the storing, retrieval and merging of of revisions. RCS is popular amongst people who create documentation and scripts. RCS allows the individual to make changes to a file and then roll back to a previous versions of the file.


Download RCS for CentOS


To install RCS to a Red Hat based Linux distribution we need to source the package: rcs-5.7-37.el6.i686.rpm

The above package can be downloaded from the following location: http://pkgs.org/centos-6-rhel-6/centos-rhel-i386/rcs-5.7-37.el6.i686.rpm/download/



Make sure you use the correct version of "rcs" for your system and distribution.

You can either manually download the file to your /tmp area or issue the "wget" command to retrieve the file for you.



[root@centos tmp]# cd /tmp
[root@centos tmp]# wget http://mirror.centos.org/centos/6/os/i386/Packages/rcs-5.7-37.el6.i686.rpm

In the following example I have downloaded an rpm package of the required software to my "/tmp" area:



[root@centos tmp]# ls -rtl
total 172
-rw-------. 1 root root      0 Apr 17 13:02 yum.log
-rw-r--r--. 1 root root 172960 Apr 23 08:42 rcs-5.7-37.el6.i686.rpm

Next we issue the installation command: rpm -ihv rcs-5.7-37.el6.i686.rpm

This command will install the rpm package with "verbose" and "hashing" options set.



[root@centos tmp]# rpm -ihv rcs-5.7-37.el6.i686.rpm
warning: rcs-5.7-37.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Preparing...                ########################################### [100%]
   1:rcs                    ########################################### [100%]

Debian Based RCS installation (Ubuntu Example)


If you are running a Debian based system, you can install the "RCS" package by issuing the following command:



john@john-desktop:~$ sudo apt-get install rcs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  mc-data libcogl9 gir1.2-json-1.0 libunity6 libbabl-0.0-0
  gir1.2-gtkclutter-1.0 libgegl-0.0-0 gir1.2-clutter-1.0 libclutter-gtk-1.0-0
  tdb-tools libcogl-common gir1.2-champlain-0.12 libclutter-1.0-0
  libchamplain-0.12-0 libcogl-pango0 libchamplain-gtk-0.12-0
  libclutter-1.0-common gir1.2-cogl-1.0 gir1.2-gtkchamplain-0.12
  gir1.2-coglpango-1.0
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed
  rcs
0 upgraded, 1 newly installed, 0 to remove and 12 not upgraded.
Need to get 365 kB of archives.
After this operation, 770 kB of additional disk space will be used.
Get:1 http://ubuntu.virginmedia.com/archive/ precise/universe rcs i386 5.7-25 [365 kB]
Fetched 365 kB in 0s (580 kB/s)
Selecting previously unselected package rcs.
(Reading database ... 840185 files and directories currently installed.)
Unpacking rcs (from .../archives/rcs_5.7-25_i386.deb) ...
Processing triggers for man-db ...
Setting up rcs (5.7-25) ...

Example of using RCS


To use a file with RCS we first need to "check the file in" using the command "ci filename, and then add a description terminated with a "." full stop.



[john@centos ~]$ ls -l
total 4
-rw-rw-r--. 1 john john 80 Apr 23 09:53 rcs_test_file.txt
[john@centos ~]$ ci rcs_test_file.txt
rcs_test_file.txt,v  <--  rcs_test_file.txt
enter description, terminated with single '.' or end of file:
NOTE: This is NOT the log message!
>> My RCS test file
>> .
initial revision: 1.1
done
[john@centos ~]$ ls -l
total 4
-r--r--r--. 1 john john 274 Apr 23 09:54 rcs_test_file.txt,v

To return the file back so that it can be read, we need to "Check Out" the file:



[john@centos ~]$ ls -l
total 4
-r--r--r--. 1 john john 274 Apr 23 09:54 rcs_test_file.txt,v
[john@centos ~]$ co rcs_test_file.txt
rcs_test_file.txt,v  -->  rcs_test_file.txt
revision 1.1
done
[john@centos ~]$ ls -l
total 8
-r--r--r--. 1 john john  80 Apr 23 10:00 rcs_test_file.txt
-r--r--r--. 1 john john 274 Apr 23 09:54 rcs_test_file.txt,v

If we needed to make changes to this "Read Only" file, we would have to first "Check Out" the file:



[john@centos ~]$ co -l rcs_test_file.txt
rcs_test_file.txt,v  -->  rcs_test_file.txt
revision 1.1 (locked)
done

One the file has been "checked out" you can now edit this file with your editor of choice. In this example I am using the "vi" editor". Once you have made your changes, you will need to save these in the usual manner.



[john@centos ~]$ vi rcs_test_file.txt
[john@centos ~]$ ls -l
total 8
-rw-r--r--. 1 john john 106 Apr 23 10:09 rcs_test_file.txt
-r--r--r--. 1 john john 284 Apr 23 10:02 rcs_test_file.txt,v

Now we need to check the file back in and "Unlock it":



[john@centos ~]$ ls -l
total 8
-rw-r--r--. 1 john john 106 Apr 23 10:09 rcs_test_file.txt
-r--r--r--. 1 john john 284 Apr 23 10:02 rcs_test_file.txt,v
[john@centos ~]$ ci -u rcs_test_file.txt
rcs_test_file.txt,v  <--  rcs_test_file.txt
new revision: 1.2; previous revision: 1.1
enter log message, terminated with single '.' or end of file:
>> Added a fourth Line of text
>> .
done


Display Information about RCS files


To display information about a RCS owned file you can use the command "rlog". "rlog" when issued with the name of a RCS file will display the following information:

RCS pathname, working pathname, head, default branch, access list, locks, symbolic names, suffix, total number of revisions and descriptive text. This is followed by entries for the selected revisions in reverse chronological order for each branch. For each revision, rlog prints revision number, author, date/time, state, number of lines added/deleted (with respect to the previous revision), locker of the revision (if any), and log message.



[john@centos ~]$ rlog rcs_test_file.txt

RCS file: rcs_test_file.txt,v
Working file: rcs_test_file.txt
head: 1.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 2;     selected revisions: 2
description:
My RCS test file
----------------------------
revision 1.2
date: 2013/04/23 09:12:08;  author: john;  state: Exp;  lines: +1 -0
Added a fourth Line of text
----------------------------
revision 1.1
date: 2013/04/23 08:54:19;  author: john;  state: Exp;
Initial revision
=============================================================================

Compare RCS Revisions


The command "rcsdiff" runs the "diff" command to compare two revisions of each RCS file given. Two compare different revisions for change we have to specify the "-r" parameter:

Example:rcsdiff -rrev1 -rrev2 rcs_filename



[john@centos ~]$ rcsdiff -r1.2 -r1.1 rcs_test_file.txt
===================================================================
RCS file: rcs_test_file.txt,v
retrieving revision 1.2
retrieving revision 1.1
diff -r1.2 -r1.1
4d3
< Add a fourth line of text

If both rev1 and rev2 are omitted, rcsdiff compares the latest revision on the default branch (by default the trunk) with the contents of the corresponding working file. This is useful for determining what you changed since the last "check in".

If rev1 is given, but rev2 is omitted, rcsdiff compares revision rev1 of the RCS file with the contents of the corresponding working file.


Displaying and Checking Out Older Versions of Files


To retrieve the contents of a previous version of a file we need to use the parameter "-r revision number" with the "Checking Out" command "co". To display a specific version of a file we use the "-p" parameter to display the specified version to your screen. First we can use the "rlog" command to display what versions are available to us:



RCS file: rcs_test_file.txt,v
Working file: rcs_test_file.txt
head: 1.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 2;     selected revisions: 2
description:
My RCS test file
----------------------------
revision 1.2
date: 2013/04/23 09:12:08;  author: john;  state: Exp;  lines: +1 -0
Added a fourth Line of text
----------------------------
revision 1.1
date: 2013/04/23 08:54:19;  author: john;  state: Exp;
Initial revision
=============================================================================

Lets display the "Initial Version" of our text file "rcs_test_file.txt":



[john@centos ~]$ co -p1.1 rcs_test_file.txt
rcs_test_file.txt,v  -->  standard output
revision 1.1
Line one of rcs test file
Line two of rcs test file
Line three of rcs test file

Now lets display Revision "1.2":



[john@centos ~]$ co -p 1.2 rcs_test_file.txt
co: RCS/1.2,v: No such file or directory
rcs_test_file.txt,v  -->  standard output
revision 1.2
Line one of rcs test file
Line two of rcs test file
Line three of rcs test file
Add a fourth line of text