CVS Information - CS 170

This page should give you a basic idea of what CVS is and how to use it. We recommend very strongly that you use something for your projects to help you manage your code. We strongly recommend either CVS or RCS.

Index:


CVS Overview


Getting Started

CVSROOT

The CVSROOT enviroment variable is used by CVS to know where to find your repository. You can set this variable each time you log in, or you can add it to your .cshrc or .profile file so that it will get set each time you log in.

Creating a CVS repository

To create a CVS repository you need to:
  1. Make the directory where the CVS repository will be.
  2. Set the enviroment variable CVSROOT to this directory. If this is not set CVS won't be able find your repository.
  3. Have CVS initialize the repository. This only needs to be done once. After that, the CVS repository is ready to use.
Example:
Step #
example% cd /home/david example% mkdir cs170/CVS 1
example% CVSROOT=/home/david/cs170/CVS
example% export CVSROOT
2
example% cvs init 3

Importing sources for the first time

After you have the repository set up, you will want to put your nachos code into it. To do this, you need to use the cvs import command.

Example:
   example% cvs import -m "Initial source" nachos/ nachos initial
Now the nachos source tree is the CVS repository. At this point, you should erase the source tree which you just added. THIS DOES NOT MEAN TO ERASE THE REPOSITORY. You want to do this so that you can check a copy of it out from the repository, since you can't use CVS with it until you do so.

Checking out

To check out a copy of your source tree from the repository:
   example% cvs checkout nachos

Commiting

When you want to commit to repository, you have a few options. You can either commit the whole tree [Example 1], or just a single file [Example 2]. (Example 1 needs to be done from the directory which holds your checked-out source tree, and Example 2 needs to be done from the directory containing the file which you wish to commit).

Example 1 (Commiting the whole tree):
   example% cvs commit nachos
Example 2 (Commiting just a single file):
   example% cvs commit thread_code.cc

Making Tags

Tags are used to give a symbolic name to a collection of file revisions. This is very useful for marking a program, at a certain stage in development. You then have the ability to later recall that version, or find out what has changed since that point.

Example (Creating a tag):
cvs tag project1 nachos
cvs commit nachos
Suppose that you are working on project 2, and you want to check out your project 1 to see if the same bug was present. You could use the following command:
Example (Checking out a tagged version):
cvs checkout -r project1 nachos
Suppose further that you are working on project 3, and you are trying to track down a nasty bug in your virtual memory code. You made a tag named proj3_membug, and then you proceeded to hack your code into little bits. You discovered where the bug is, but now you want to revert your virtual memory code back to it's proj3_membug state, so that you can fix it and get rid of all of your debugging printf statements. You could use the following command:
Example (Updating to a tagged version of a file):
cvs update -r proj3_membug virtualMemory.cc


Essential Commands

cvs provides a rich variety of commands (cvs_command in the Synopsis), each of which often has a wealth of options, to satisfy the many needs of source management in distributed environments. However, you don't have to master every detail to do useful work with cvs; in fact, five commands are sufficient to use (and contribute to) the source repository.
cvs checkout modules...
A necessary preliminary for most cvs work: creates your private copy of the source for modules (named collections of source; you can also use a path relative to the source repository here). You can work with this copy without interfering with others' work. At least one subdirectory level is always created.
cvs update
Execute this command from within your private source directory when you wish to update your copies of source files from changes that other developers have made to the source in the repository.
cvs add file...
Use this command to enroll new files in cvs records of your working directory. The files will be added to the repository the next time you run `cvs commit' Note: You should use the `cvs import' command to bootstrap new sources into the source repository. `cvs add' is only used for new files to an already checked-out module.
cvs remove file...
Use this command (after erasing any files listed) to declare that you wish to eliminate files from the repository. The removal does not affect others until you run `cvs commit'
cvs commit file...
Use this command when you wish to ``publish'' your changes to other developers, by incorporating them in the source repository.

Command Details

Here are details on some of the cvs commands and the options each accepts. The summary lines at the top of each command's description highlight three kinds of things:
    Command Options and Arguments
Special options are described in detail below; common command options may appear only in the summary line.
    Working Directory, or Repository?
Some cvs commands require a working directory to operate; some require a repository. Also, some commands change the repository, some change the working directory, and some change nothing.
    Synonyms
Many commands have synonyms, which you may find easier to remember (or type) than the principal name.

add [-k kflag] [-m 'message'] files...
Requires: repository, working directory.
Changes: working directory.
Synonym: new
Use the add command to create a new file or directory in the source repository. The files or directories specified with add must already exist in the current directory (which must have been created with the checkout command). To add a whole new directory hierarchy to the source repository (for example, files received from a third-party vendor), use the `cvs import' command instead.

If the argument to `cvs add' refers to an immediate sub-directory, the directory is created at the correct place in the source repository, and the necessary cvs administration files are created in your working directory. If the directory already exists in the source repository, `cvs add' still creates the administration files in your version of the directory. This allows you to use `cvs add' to add a particular directory to your private sources even if someone else created that directory after your checkout of the sources. You can do the following:


example% mkdir new_directory
example% cvs add new_directory
example% cvs update new_directory

An alternate approach using `cvs update' might be:


example% cvs update -d new_directory

(To add any available new directories to your working directory, it's probably simpler to use `cvs checkout' or `cvs update -d')

The added files are not placed in the source repository until you use `cvs commit' to make the change permanent. Doing a `cvs add' on a file that was removed with the `cvs remove' command will resurrect the file, if no `cvs commit' command intervened.

You will have the opportunity to specify a logging message, as usual, when you use `cvs commit' to make the new file permanent. If you'd like to have another logging message associated with just creation of the file (for example, to describe the file's purpose), you can specify it with the `-m message' option to the add command.

The `-k kflag' option specifies the default way that this file will be checked out. The `kflag' argument is stored in the RCS file and can be changed with `cvs admin' Specifying `-ko' is useful for checking in binaries that shouldn't have keywords expanded.

checkout [options] modules...
Requires: repository.
Changes: working directory.
Synonyms: co, get
Make a working directory containing copies of the source files specified by modules. You must execute `cvs checkout' before using most of the other cvs commands, since most of them operate on your working directory.

modules are either symbolic names (themselves defined as the module `modules' in the source repository; see cvs(5) ) for some collection of source directories and files, or paths to directories or files in the repository.

Depending on the modules you specify, checkout may recursively create directories and populate them with the appropriate source files. You can then edit these source files at any time (regardless of whether other software developers are editing their own copies of the sources); update them to include new changes applied by others to the source repository; or commit your work as a permanent change to the repository.

Note that checkout is used to create directories. The top-level directory created is always added to the directory where checkout is invoked, and usually has the same name as the specified module. In the case of a module alias, the created sub-directory may have a different name, but you can be sure that it will be a sub-directory, and that checkout will show the relative path leading to each file as it is extracted into your private work area (unless you specify the -Q global option).

Running `cvs checkout' on a directory that was already built by a prior checkout is also permitted, and has the same effect as specifying the -d option to the update command described below.

The options permitted with `cvs checkout' include the standard command options -P, -f, -k kflag , -l, -n, -p, -r tag, and -D date.

In addition to those, you can use these special command options with checkout:

Use the -A option to reset any sticky tags, dates, or -k options. (If you get a working file using one of the -r, -D, or -k options, cvs remembers the corresponding tag, date, or kflag and continues using it on future updates; use the -A option to make cvs forget these specifications, and retrieve the ``head'' version of the file).

The -j branch option merges the changes made between the resulting revision and the revision that it is based on (e.g., if the tag refers to a branch, cvs will merge all changes made in that branch into your working file).

With two -j options, cvs will merge in the changes between the two respective revisions. This can be used to ``remove'' a certain delta from your working file.

In addition, each -j option can contain on optional date specification which, when used with branches, can limit the chosen revision to one within a specific date. An optional date is specified by adding a colon (:) to the tag. An example might be what `cvs import' tells you to do when you have just imported sources that have conflicts with local changes:


example% cvs checkout -jTAG:yesterday -jTAG module

Use the -N option with `-d dir' to avoid shortening module paths in your working directory. (Normally, cvs shortens paths as much as possible when you specify an explicit target directory.)

Use the -c option to copy the module file, sorted, to the standard output, instead of creating or modifying any files or directories in your working directory.

Use the -d dir option to create a directory called dir for the working files, instead of using the module name. Unless you also use -N, the paths created under dir will be as short as possible.

Use the -s option to display per-module status information stored with the -s option within the modules file.

commit [-lnR] [-m 'log_message' | -f file] [-r revision] [files...]
Requires: working directory, repository.
Changes: repository.
Synonym: ci
Use `cvs commit' when you want to incorporate changes from your working source files into the general source repository.

If you don't specify particular files to commit, all of the files in your working current directory are examined. commit is careful to change in the repository only those files that you have really changed. By default (or if you explicitly specify the -R option), files in subdirectories are also examined and committed if they have changed; you can use the -l option to limit commit to the current directory only. Sometimes you may want to force a file to be committed even though it is unchanged; this is achieved with the -f flag, which also has the effect of disabling recursion (you can turn it back on with -R of course).

commit verifies that the selected files are up to date with the current revisions in the source repository; it will notify you, and exit without committing, if any of the specified files must be made current first with `cvs update' commit does not call the update command for you, but rather leaves that for you to do when the time is right.

When all is well, an editor is invoked to allow you to enter a log message that will be written to one or more logging programs and placed in the source repository file. You can instead specify the log message on the command line with the -m option, thus suppressing the editor invocation, or use the -F option to specify that the argument file contains the log message.

The -r option can be used to commit to a particular symbolic or numeric revision. For example, to bring all your files up to the revision ``3.0'' (including those that haven't changed), you might do:


example% cvs commit -r3.0

cvs will only allow you to commit to a revision that is on the main trunk (a revision with a single dot). However, you can also commit to a branch revision (one that has an even number of dots) with the -r option. To create a branch revision, one typically use the -b option of the rtag or tag commands. Then, either checkout or update can be used to base your sources on the newly created branch. From that point on, all commit changes made within these working sources will be automatically added to a branch revision, thereby not perturbing main-line development in any way. For example, if you had to create a patch to the 1.2 version of the product, even though the 2.0 version is already under development, you might do:


example% cvs rtag -b -rFCS1_2 FCS1_2_Patch product_module
example% cvs checkout -rFCS1_2_Patch product_module
example% cd product_module
[[ hack away ]]
example% cvs commit

Say you have been working on some extremely experimental software, based on whatever revision you happened to checkout last week. If others in your group would like to work on this software with you, but without disturbing main-line development, you could commit your change to a new branch. Others can then checkout your experimental stuff and utilize the full benefit of cvs conflict resolution. The scenario might look like:


example% cvs tag -b EXPR1
example% cvs update -rEXPR1
[[ hack away ]]
example% cvs commit

Others would simply do `cvs checkout -rEXPR1 whatever_module' to work with you on the experimental change.

diff [-kl] [rcsdiff_options] [[-r rev1 | -D date1] [-r rev2 | -D date2]] [files...]
Requires: working directory, repository.
Changes: nothing.
You can compare your working files with revisions in the source repository, with the `cvs diff' command. If you don't specify a particular revision, your files are compared with the revisions they were based on. You can also use the standard cvs command option -r to specify a particular revision to compare your files with. Finally, if you use -r twice, you can see differences between two revisions in the repository. You can also specify -D options to diff against a revision in the past. The -r and -D options can be mixed together with at most two options ever specified.

See rcsdiff(1) for a list of other accepted options.

If you don't specify any files, diff will display differences for all those files in the current directory (and its subdirectories, unless you use the standard option -l) that differ from the corresponding revision in the source repository (i.e. files that you have changed), or that differ from the revision specified.

import [-options] repository vendortag releasetag...
Requires: Repository, source distribution directory.
Changes: repository.
Use `cvs import' to incorporate an entire source distribution from an outside source (e.g., a source vendor) into your source repository directory. You can use this command both for initial creation of a repository, and for wholesale updates to the module form the outside source.

The repository argument gives a directory name (or a path to a directory) under the CVS root directory for repositories; if the directory did not exist, import creates it.

When you use import for updates to source that has been modified in your source repository (since a prior import), it will notify you of any files that conflict in the two branches of development; use `cvs checkout -j' to reconcile the differences, as import instructs you to do.

By default, certain file names are ignored during `cvs import' names associated with CVS administration, or with other common source control systems; common names for patch files, object files, archive files, and editor backup files; and other names that are usually artifacts of assorted utilities. For an up to date list of ignored file names, see the Cederqvist manual (as described in the SEE ALSO section of this manpage).

The outside source is saved in a first-level branch, by default `1.1.1' Updates are leaves of this branch; for example, files from the first imported collection of source will be revision `1.1.1.1' then files from the first imported update will be revision `1.1.1.2' and so on.

At least three arguments are required. repository is needed to identify the collection of source. vendortag is a tag for the entire branch (e.g., for `1.1.1'. You must also specify at least one releasetag to identify the files at the leaves created each time you execute `cvs import'

One of the standard cvs command options is available: -m message. If you do not specify a logging message with -m, your editor is invoked (as with commit) to allow you to enter one.

There are three additional special options.

Use `-d' to specify that each file's time of last modification should be used for the checkin date and time.

Use `-b branch' to specify a first-level branch other than `1.1.1'

Use `-I name' to specify file names that should be ignored during import. You can use this option repeatedly. To avoid ignoring any files at all (even those ignored by default), specify `-I !'

remove [-lR] [files...]
Requires: Working directory.
Changes: Working directory.
Synonyms: rm, delete
Use this command to declare that you wish to remove files from the source repository. Like most cvs commands, `cvs remove' works on files in your working directory, not directly on the repository. As a safeguard, it also requires that you first erase the specified files from your working directory.

The files are not actually removed until you apply your changes to the repository with commit; at that point, the corresponding RCS files in the source repository are moved into the `Attic' directory (also within the source repository).

This command is recursive by default, scheduling all physically removed files that it finds for removal by the next commit. Use the -l option to avoid this recursion, or just specify that actual files that you wish remove to consider.

status [-lRqQ] [-v] [files...]
Requires: working directory, repository.
Changes: nothing.
Display a brief report on the current status of files with respect to the source repository, including any ``sticky'' tags, dates, or -k options. (``Sticky'' options will restrict how `cvs update' operates until you reset them; see the description of `cvs update -A...')

You can also use this command to anticipate the potential impact of a `cvs update' on your working source directory. If you do not specify any files explicitly, reports are shown for all files that cvs has placed in your working directory. You can limit the scope of this search to the current directory itself (not its subdirectories) with the standard -l option flag; or you can explicitly request recursive status reports with the -R option.

The -v option causes the symbolic tags for the RCS file to be displayed as well.

tag [-lQqR] [-F] [-b] [-d] [-r tag | -D date] [-f] symbolic_tag [files...]
Requires: working directory, repository.
Changes: repository.
Synonym: freeze
Use this command to assign symbolic tags to the nearest repository versions to your working sources. The tags are applied immediately to the repository, as with rtag.

One use for tags is to record a ``snapshot'' of the current sources when the software freeze date of a project arrives. As bugs are fixed after the freeze date, only those changed sources that are to be part of the release need be re-tagged.

The symbolic tags are meant to permanently record which revisions of which files were used in creating a software distribution. The checkout, export and update commands allow you to extract an exact copy of a tagged release at any time in the future, regardless of whether files have been changed, added, or removed since the release was tagged.

You can use the standard -r and -D options to tag only those files that already contain a certain tag. This method would be used to rename a tag: tag only the files identified by the old tag, then delete the old tag, leaving the new tag on exactly the same files as the old tag.

Specifying the -f flag in addition to the -r or -D flags will tag those files named on the command line even if they do not contain the old tag or did not exist on the specified date.

By default (without a -r or -D flag) the versions to be tagged are supplied implicitly by the cvs records of your working files' history rather than applied explicitly.

If you use `cvs tag -d symbolic_tag...' the symbolic tag you specify is deleted instead of being added. Warning: Be very certain of your ground before you delete a tag; doing this effectively discards some historical information, which may later turn out to have been valuable.

`cvs tag' will not move a tag that already exists. With the -F option, however, `cvs tag' will re-locate any instance of symbolic_tag that already exists on that file to the new repository versions. Without the -F option, attempting to use `cvs tag' to apply a tag that already exists on that file will produce an error message.

The -b option makes the tag a ``branch'' tag, allowing concurrent, isolated development. This is most useful for creating a patch to a previously released software distribution.

Normally, tag executes recursively through subdirectories; you can prevent this by using the standard -l option, or specify the recursion explicitly by using -R.

update [-AdflPpQqR] [-d] [-r tag|-D date] files...
Requires: repository, working directory.
Changes: working directory.
After you've run checkout to create your private copy of source from the common repository, other developers will continue changing the central source. From time to time, when it is convenient in your development process, you can use the update command from within your working directory to reconcile your work with any revisions applied to the source repository since your last checkout or update.

update keeps you informed of its progress by printing a line for each file, prefaced with one of the characters `U A R M C ?' to indicate the status of the file:

U file
The file was brought up to date with respect to the repository. This is done for any file that exists in the repository but not in your source, and for files that you haven't changed but are not the most recent versions available in the repository.
A file
The file has been added to your private copy of the sources, and will be added to the source repository when you run `cvs commit' on the file. This is a reminder to you that the file needs to be committed.
R file
The file has been removed from your private copy of the sources, and will be removed from the source repository when you run `cvs commit' on the file. This is a reminder to you that the file needs to be committed.
M file
The file is modified in your working directory. `M' can indicate one of two states for a file you're working on: either there were no modifications to the same file in the repository, so that your file remains as you last saw it; or there were modifications in the repository as well as in your copy, but they were merged successfully, without conflict, in your working directory.
C file
A conflict was detected while trying to merge your changes to file with changes from the source repository. file (the copy in your working directory) is now the result of merging the two versions; an unmodified copy of your file is also in your working directory, with the name `.#file.version', where version is the revision that your modified file started from. (Note that some systems automatically purge files that begin with `.#' if they have not been accessed for a few days. If you intend to keep a copy of your original file, it is a very good idea to rename it.)
? file
file is in your working directory, but does not correspond to anything in the source repository, and is not in the list of files for cvs to ignore (see the description of the -I option).

Use the -A option to reset any sticky tags, dates, or -k options. (If you get a working copy of a file by using one of the -r, -D, or -k options, cvs remembers the corresponding tag, date, or kflag and continues using it on future updates; use the -A option to make cvs forget these specifications, and retrieve the ``head'' version of the file).

The -jbranch option merges the changes made between the resulting revision and the revision that it is based on (e.g., if the tag refers to a branch, cvs will merge all changes made in that branch into your working file).

With two -j options, cvs will merge in the changes between the two respective revisions. This can be used to ``remove'' a certain delta from your working file. E.g., If the file foo.c is based on revision 1.6 and I want to remove the changes made between 1.3 and 1.5, I might do:


example% cvs update -j1.5 -j1.3 foo.c    # note the order...

In addition, each -j option can contain on optional date specification which, when used with branches, can limit the chosen revision to one within a specific date. An optional date is specified by adding a colon (:) to the tag.


-jSymbolic_Tag:Date_Specifier

Use the -d option to create any directories that exist in the repository if they're missing from the working directory. (Normally, update acts only on directories and files that were already enrolled in your working directory.) This is useful for updating directories that were created in the repository since the initial checkout; but it has an unfortunate side effect. If you deliberately avoided certain directories in the repository when you created your working directory (either through use of a module name or by listing explicitly the files and directories you wanted on the command line), then updating with -d will create those directories, which may not be what you want.

Use -I name to ignore files whose names match name (in your working directory) during the update. You can specify -I more than once on the command line to specify several files to ignore. By default, update ignores files whose names match certain patterns; for an up to date list of ignored file names, see the Cederqvist manual (as described in the SEE ALSO section of this manpage).

Use `-I !' to avoid ignoring any files at all.

The standard cvs command options -f, -k, -l, -P, -p, and -r are also available with update.



Help!!

If you have any more questions pertaining to CS170 and CVS, please email: David Watson <david@cs.ucsb.edu>


Useful Documentation