User Tools

Site Tools


linux:rcs

Revision Control with RCS

RCS is a small but handy Revision Control System i.e. for shellscripts or config files.

Install

(~/scripts) skull@dc:$sudo yum install rcs rcs-docs

Usage

Initial Commit

Create a directory called RCS

(~/scripts) skull@dc:$mkdir RCS

Commit your desired file

(~/scripts) skull@dc:$ ci -i grepall.sh
RCS/grepall.sh,v  <--  grepall.sh
enter description, terminated with single '.' or end of file:
NOTE: This is NOT the log message!
>> Initial Commit
>> .
initial revision: 1.1
done

Now the file is stored in the RCS Directory. To get it back we have to check the file out. In Order to make sure that no ones makes changes we lock the file after the checkout.

(~/scripts) skull@dc:$ co grepall.sh
RCS/grepall.sh,v  -->  grepall.sh
revision 1.1
done
(~/scripts) skull@dc:$ co -l grepall.sh
RCS/grepall.sh,v  -->  grepall.sh
revision 1.1 (locked)
done

Commiting changes

Make sure you correctly checked out the file and that its locked. Make your changes and commit the new version with:

(~/scripts) skull@dc:$ ci -u grepall.sh
RCS/grepall.sh,v  <--  grepall.sh
new revision: 1.2; previous revision: 1.1
enter log message, terminated with single '.' or end of file:
>> Revisionsdatum angepasst
>> .
done

Don't forget to lock your File again afterwards!

(~/scripts) skull@dc:$ co -l grepall.sh
RCS/grepall.sh,v  -->  grepall.sh
revision 1.2 (locked)
done

Alternatively you can check in with -l after your edit. That locks the file automatically for you.

       -l[rev]
              works like -r, except it performs an additional co -l for the deposited revision.  Thus, the deposited revision is immediately checked out again and locked.  This is useful
              for saving a revision although one wants to continue editing it after the checkin.
(~/scripts) skull@dc:$ vi grepall.sh
(~/scripts) skull@dc:$ ci -l grepall.sh
RCS/grepall.sh,v  <--  grepall.sh
new revision: 1.3; previous revision: 1.2
enter log message, terminated with single '.' or end of file:
>> just for testing
>> .
done

Recovering earlier Versions

rcsdiff

To keep track of the changes use rcsdiff In this example the current working file gets compared to the latest commit.

(~/scripts) skull@dc:$ rcsdiff grepall.sh
===================================================================
RCS file: RCS/grepall.sh,v
retrieving revision 1.3
diff -r1.3 grepall.sh
18c18
< #       VERSION:  1.3  Revisionsdatum
---
> #       VERSION:  1.4 Added proper exit status
26a27
>       exit 0
29d29
< # asdf

To compare two other Versions use the -r switch

(~/scripts) skull@dc:$ rcsdiff -r1.4 -r1.1 grepall.sh
===================================================================
RCS file: RCS/grepall.sh,v
retrieving revision 1.4
retrieving revision 1.1
diff -r1.4 -r1.1
18c18
< #       VERSION:  1.4 Added proper exit status
---
> #       VERSION:  1.1 Kommentarzeilen entfernt
20c20
< #      REVISION:  15.04.2012
---
> #      REVISION:  ---
27d26
<       exit 0
(~/scripts) skull@dc:$

rcs2log

(~/scripts) skull@dc:$ rcs2log grepall.sh
2012-04-15  skull  <skull@dc.lan.darktemple.ch>
 
        * grepall.sh: Added proper exit status
 
        * grepall.sh: just for testing
 
        * grepall.sh: Revisionsdatum angepasst
 
        * grepall.sh: New file.

To display the correspondenting version use -v

(~/scripts) skull@dc:$ rcs2log -v grepall.sh
2012-04-15  skull  <skull@dc.lan.darktemple.ch>
 
        * grepall.sh 1.4: Added proper exit status
 
        * grepall.sh 1.3: just for testing
 
        * grepall.sh 1.2: Revisionsdatum angepasst
 
        * grepall.sh 1.1: New file.

Retrieving the older revision

To actually get our old revision back we just have to \\co -l -r[version] filename \\to get the old revision back into the working folder, locked.
To do it unlocket the proper command is \\co -u -r[version] filename

(~/scripts) skull@dc:$ co -u -r1.4 grepall.sh
RCS/grepall.sh,v  -->  grepall.sh
co: RCS/grepall.sh,v: multiple revisions locked by skull; please specify one
revision 1.4 (unlocked)
writable grepall.sh exists; remove it? [ny](n): y
done

Then commit it again to make sure the actual version is correct.

(~/scripts) skull@dc:$ ci -u -r1.6 grepall.sh
RCS/grepall.sh,v  <--  grepall.sh
new revision: 1.6; previous revision: 1.5
enter log message, terminated with single '.' or end of file:
>> Reverted back to 1.4
>> .
done

File Locking

In RCS you lock your files before you edit them. This happens to assure that no one can make changes while you are making changes. However, it's possible that you forget to lock a file before you edit it. Or that you acccidentaly have two locked versions.

To manually unlock a release:

(~/scripts) skull@dc:$ rcs -u[rev] grepall.sh

To manually lock a release:

(~/scripts) skull@dc:$ rcs -l[rev] grepall.sh

The $Id field

RCS has a nice feature to label your files automatically.
Just add the following as a comment into your file:

 # $Id:  filename  revision  date  time  author  state  $ 

RCS automatically recognises the pattern and labes your files from now on.
This is very handy because now you always see which file exactly you're working on.

After we ci -l the file we have a perfect labeling inside our file:

 # $Id: grepall.sh,v 1.8 2012/04/15 14:27:03 skull Exp skull $

If you are using the Bash Script Plugin for vim it is a good idea to already set this id field in your template!

Command Summary

RCS COMMAND SUMMARY
==========================================================================================================================
rcs -i file.sh                  # Create and initilize a new RCS file, but do not deposit any revision.
rcs -l[rev] file.sh             # Lock the [rev]
rcs -u[rev] file.sh             # Unlock the [rev]
--------------------------------------------------------------------------------------------------------------------------
ci -i file.sh                   # Initialize rcs for file.sh
ci -l file.sh                   # checks the file in and does an additional check out, leaving the file locked (co -l)
ci -u file.sh                   # checks in the new file and does an additional check out (co) without locking the file.
--------------------------------------------------------------------------------------------------------------------------
co file.sh                      # check out the latest revision
co -l file.sh                   # check out the latest revision and lock it
--------------------------------------------------------------------------------------------------------------------------
rcs2log -v file.sh              # Gives a History of all the commits, including Version Number (-v)
--------------------------------------------------------------------------------------------------------------------------
rcsdiff file.sh                 # Gives out the changes between the latest commit and the current working file.
rcsdiff -r1.1 -r1.4 file.sh     # Gives out the changes between release 1.1 and 1.4
linux/rcs.txt · Last modified: 2012/04/15 18:12 by skull@darktemple.ch