Guide to CVS

This document is licensed under the Creative Commons Attribution Share-Alike License 2.0. The original was written for

What is CVS?

CVS is the Concurrent Versions System. It lets multiple people work on the same set of project files at the same time without clobbering each others' changes, and it keeps track of who made what changes made to those files. CVS works by keeping a repository—a master copy—of the project files. Each contributor checks out a copy of the project files, makes his/her modifications, and then checks in or commits the changes: CVS compares the contributor's version to the master copy, figures out what changed, and then changes those lines in the master copy to match, ignoring any changes made by other people to other parts of the file. In case of a conflict, CVS aborts the check-in and reports the conflicts so that they can be manually resolved before trying again.

Using Command-line CVS

Setting $CVSROOT

Before you can do anything with cvs, you first need to tell it where to find the repository you're working with. There are two main ways of doing this: using the $CVSROOT environment variable or using the -d option. Setting the $CVSROOT environment variable is usually the most convenient because then you only have to type it once; subsequent cvs commands will all use that $CVSROOT setting.

set CVSROOT=cvsroot-string
export CVSROOT=cvsroot-string
setenv CVSROOT cvsroot-string

where cvsroot-string is of the form :protocol:username@server:/path-to-repository. (The cvsroot-string for anonymous read-only access to is

To use -d instead, add -d cvsroot-string as the first argument after 'cvs' in each cvs command. For example:

cvs -d co CSS

Logging in

cvs login

You will be prompted for your password. (For anonymous access, the password is anonymous.) CVS encrypts your passwords in a .cvspass file in your home directory, so you only need to log in once. If CVS complains about you not having a home directory, it's probably because you need to set the $HOME environment variable to a reasonable directory path.

Checking out

To check out files from the repository, first cd to the directory where you want to keep the files, then type

cvs -z3 co path

where path is the path to the file/directory you want to check out or a module name.

For example,

cvs -z3 co CSS
cvs -z3 co CSS/CSS2.1-test-suite/README

The -z3 parameter is to cause the files (and diffs) to be compressed while in transit. This is almost always the right thing to do; so much so that you should probably just put cvs -z3 in your $HOME/.cvsrc file, to make it be the default on all CVS commands.

(Note that -z9 offers a logarithmic improvement in compression at an exponential cost in CPU time. Therefore, we recommend -z3; that seems to be about optimal in most cases.)

If the -z3 parameter doesn't work, that means you don't have cvs and/or gzip installed correctly. Your life will be much easier if you correct this, rather than omitting that parameter.

Creating a Patch

A patch is a diff file that lists all the changes you've made to your project files so that other people can review your changes, apply them to their own tree and test them, and/or check them in for you. You will need to know the names of all the files you've changed so that you can tell cvs which files to compare.


To create a patch, type

cvs diff -pu path/to/file1 path/to/file2 ... > patch.out

The last part (> patch.out) dumps the output of that command to the file patch.out. If you leave it out, cvs will just print everything to the screen.

More Context

Some reviewers prefer having a bit more context for each of the changes:

cvs diff -pu8 path/to/file1 path/to/file2 ... > patch.out

The 8 after the u asks for 8 lines of context instead of the usual 3.

Ignoring Whitespace

If you're making a lot of whitespace/indentation changes, it's often helpful to review a patch with all the whitespace changes ignored so you can focus on what actual content has changed.

cvs diff -pu8w path/to/file1 path/to/file2 ... > patch.out

If you're creating a new file, you can add that change to the diff as well. First, open up the CVS/Entries file that's in the new file's directory. Add the following line to it:

/filename/0/dummy timestamp//

Now you can include the new file in your diff by using the -N option:

cvs diff -pu8N path/to/file1 path/to/file2 ... > patch.out

Committing Changes

Always run the cvs diff command and check it's output before committing your changes to the tree. You will catch many mistakes before they happen this way.

cvs diff -pu path/to/file1 path/to/file2 ...

The command for committing changes (“checking in”) to the repository is similar to the diff command: you list all the files that have changed:

cvs commit -m "comment" path/to/file1 path/to/file2 ...

The comment should include the reviewer (r=someone and the patch author (patch by if written by someone besides you.

Adding New Files

To add a file to the tree, first cd to its parent directory then type

cvs add filename

Then commit the addition as with other changes.

If the file is binary, you must cvs add with the -kb options.

cvs add -kb filename

Removing Files

To remove a file from the tree, first delete your own copy, then, from its parent directory, issue the command

cvs remove filename

As with adding files, you must commit this change.

CVS will still keep the revision history for the removed file.

test/cvs.txt · Last modified: 2014/12/09 15:48 by
Recent changes RSS feed Valid XHTML 1.0 Valid CSS Driven by DokuWiki