There are two commands that are used on a regular basis, ci
("check-in") and co ("check-out"). The following sections
provide some tutorials on using the different options. The manual pages
are the typically concise Unix manual pages -- but they are accurate.
It is useful to have the manual pages in front of you as you go through
this to correlate the language in the manual with the examples that
follow.
It is time to explicitly define the terminology. It is straight-forward, although somehow confusion arises when actually doing things.
ci command. To be able to check something in, you
must have locked the file first or you must be creating the RCS file for
the first time.
Once a file is under RCS control, you can get access to it for either reading or writing. If you only intend to print the file, compile it, search for something, etc, you should check it out unlocked. If you want to change the file, check it out locked. Usually, just check a file out unlocked.
To check out a file without a lock, just say
co test.c
this retrieves the most recent revision of the file (obtained from `RCS/test.c,v') and deposits it in your current directory. The access permission on the file is read only. This is a reminder that the file is not locked, and prevent users from changing the file (Note: you could do `chmod u+w file.c', but in that case why not just check it out locked?).
To check out a file with a lock:
co -l test.c
the `-l' stands for "locked". When a file has been checked out locked, you are given write permission. RCS may say `File locked by somebody', in which case one must negotiate with that person because they have the file locked.
There are many ways to specify which revision of a file to check out (either locked or unlocked). You can specify a specific revision number, symbolic name, date, state or author.
rlog to help you select which revision you want.
co -r1.3 test.cretrieves revision 1.3 of the file `test.c'. If multiple files are specified,
co -r1.3 test1.c test2.c test3.cthen RCS would retrieve revision 1.3 of each of the files, probably not what is wanted.
co -rVersion_1 test.cUse of symbolic names is especially useful for a group of files.
co -rVersion_1 test1.c test2.c test3.cgets the appropriate revision of the three files needed to create Version_1.
co is very smart about determining what time you actually meant.
The following forms are all understood:
co -d"22-April-1982, 17:20-PDT" test.c co -d"2:25 AM, Dec. 29, 1983" test.c co -d"Tue-PDT, 1981, 4pm Jul 21" test.cNote the use of quotes to keep the date as one argument. If a time is not completely specified, then default values are assigned.
Exp for experimental. The other common state
is Rel for released. If you specify a state, such as:
co -sRel test.cthen RCS finds the most recent revision with state
Rel and checks
it out. If you had the following revisions, each with the given state
then RCS would check out revision 1.11, skipping revisions 1.12 and 2.0.
co -wpete test.cgets the latest revision by
pete. Whereas
co -w test.cgets the latest revision checked in by you.
All of these options can be combined. The first revision that matches
all the requirements is checked out. If there are no revisions that
match, then nothing is checked out and an error message is printed.
The -l option can also be used with the above to check out the
selected revision with a lock. Usually, only the -r option is
used, the others involving author, date, state are marginally useful.
To take a quick look at a revision, the -p for `print'
option specifies the file be sent to the screen. This is useful if you
want a quick look at an old revision of the file, but don't want to
overwrite the existing version. All the above flags except -l
are available.
Frequently it is useful to maintain some information in a source file such as who recently made a change and when that change occurred. A further refinement is to arrange for this information to be compiled into the code. This is used to determine exactly which versions of a file went into making an executable if there are bugs in the executable.
RCS will automatically add text into your source when certain
keywords present. Keywords are of the form $Keyword:$ where everything
between the : and $ is replaced with the RCS values.
Keywords and their values are:
$Author:$
$Date:$
$Header:$
#ifndef lint static char RCSid[] = "$Header:$"; #endifIt is surrounded with the
#ifdef lint ... #endif because lint
would complain about an unused variable RCSid and about
RCSid being multiply defined. The variable is static so it will
be unique to this object file and not available to any others. Upon
being expanded it looks like:
static char RCSid[] = "$Header: test.c,v 1.2 87/2/4 09:39:07 pete Exp $";This incorporates all the other information that keywords give except for the log message.
$Locker:$
$Log:$
$Log:$. This accumulates a history of all the changes in the
source file.
$Revision:$
$Source:$
$State:$
rcs -s or ci -s
The following example includes all the above:
/* * $Author: pete $ * $Date: 87/04/02 14:14:52 $ * $Header: test.c,v 1.2 87/04/02 14:14:52 pete Locked $ * $Locker: pete $ * $Log: test.c,v $ * Revision 1.2 87/04/02 14:14:52 pete * Misspelt Revision keyword. * * Revision 1.1 87/04/02 14:13:27 pete * Initial revision * * $Revision: 1.2 $ * $Source: /u0/pete/src/doc/RCS/test.c,v $ * $State: Exp $ */
The above are placed in a comment block, because that is the typical usage. The keywords substitutions occur wherever a keyword is located in the file. This keyword substition occurs at check out time, not at check in time.
To be able to check in a file, you must first have checked it out locked or
it must be the initial (first time) check in. When you check a file in,
you are prompted for a log message which should be one or two lines long
(although it depends on how many changes you've made). The intention of
the log messages is to remind yourself and inform others what the
significant differences are between this revision and the previous
revision. You terminate the log message with a . as the only
character on a line or by entering ^D (EOF).
If the file has never been checked into RCS, you are prompted for an
initial message which should be some descriptive text describing what the
file is for. This has limited usefullness since the text cannot be
included in the source file, and the source file should already be
documented. In other words, it is acceptable to leave this empty. You
terminate the initial message the same way as the log message: with a
. on a line by itself or by entering ^D (EOF).
If you intend to edit the file immediatly after checking it in, use the
-l flag (lock), which checks the file out with a lock immediatly
after checking it in. If you want the file to stick around in the current
directory, use the -u flag (unlock) to have it checked out
without a lock immediatly after the check in.
If you are checking in a group of files and want the same log message for each file, try:
ci -m"Renamed variable v to velocity." test1.c test2. test3.c
and RCS will use the `Renamed ... velocity.' for the log message for all the files.
If you want to give a symbolic name to this revision, now is the best time to do so.
ci -NVersion_1 test1.c test2.c test3.c
You are limited to alphanumeric characters, -, and _. Each
of the above files then has Version_1 as the name for the revision. This
is used in configuration management to allow multiple versions of
software to exist. You can also use this in a similar manner to maintain
multiple versions of your programs. RCS enforces the restriction that a
single name can refer to only one revision. A single revision can be
known by more than one name. You can use the rcs command,
described later, to assing symbolic names after the fact.
The state of the revision is assigned at this point. By default it is
set to Exp for experimental. To change the default value, you
must use the -s flag.
ci -sReleased test1.c
You can also give the revision number when you check in a file. Usually you just use RCS's default rules. Occasionally you want to increment the main branch number, say from 1.23 to 2.0, then you would type in:
ci -r2.0 test1.c
and the new revison would be 2.0. The specified revision number must be
greater than any other revision number. In the above case, you could not
check it in as -r1.13 even if there was no revision 1.13.
Sooner or later, you are going to attempt to check in a file that you have
not locked. Theoretically, this should never happen, since you should
always do a co -l before editing a file.
You need to find out if the file is already locked by somebody else or is
not locked at all. If it is locked by someone, there are two choices: if
you have added changes on top of the other persons and your changes are
much smaller then the other persons, then let the other person check the
file in; if the other person's changes are less than your changes, then
have the other person do a rcs -u filename to unlock the RCS file
and then you do a rcs -l filename to lock the file. You can then
check the file in with ci.
If the file is not locked, then simply do a rcs -l filename to
lock the file and then check it in using ci. However, be careful
somebody else has not added a revision between the time you got your
version of the file and the time you check it in. You can use the
rlog command to see anything anybody else has done or you can use
rcsdiff to compare the your revision of the file with the current
RCS revision.
Go to the first, previous, next, last section, table of contents.