Concurrent Versions System (CVS)

Concurrent Versions System (CVS) is an open-source version control system that offers many advantages over more expensive systems.  One of the most useful features is branching and merging of entire source trees.  CVS has a learning curve, like any concept or tool, and one of the biggest differences between it and other version control systems is that developers do not have to explicitly checkout files.  Instead, a developer retrieves all the files for a project, changes them, and then commits the changes to the repository.  More information on individual CVS commands and usage can be found at:

CVS Setup

The CVS client for Windows operating systems can be downloaded from http://www.cvshome.org/dev/codewindow.html.  Extract the cvs.exe file from the ZIP archive, and place it somewhere on the path, such as C:\Windows.

Anytime a developer uses CVS, the location of the repository, or CVSROOT, must be defined.  A CVSROOT has this format:

:protocol:userid@host:location

The CVSROOT can be set for all CVS commands by setting it as an environment variable or individually for each cvs command using the -d option.  This is how to set the CVSROOT to a local CVS repository:

set CVSROOT=:pserver:bonhamcm@localhost:C:\CVSROOT (Windows)
or
export CVSROOT=:pserver:bonhamcm@localhost:C:\CVSROOT (UNIX bash shell)

Here's how to set the CVSROOT for an individual CVS command:

C:\>cvs -d :pserver:bonhamcm@localhost:C:\CVSROOT login

CVS Commands

All the CVS commands are executed from the cvs executable file.  Here's the general format of a CVS command:

cvs [global options] command [command options] [command parameters]

Here are a few of the most commonly used commands:

login

Before executing any other CVS commands, the user must login to the CVS repository. When using the pserver protocol, CVS will prompt the user for the password.  Here's an example:

C:\>cvs -d :pserver:bonhamcm@localhost:C:\CVSROOT login
Logging in to :pserver:bonhamcm@localhost:2401C:\CVSROOT
CVS password: ***

import

A module must first be imported into the CVS repository before it can be used.  For a new project, create the directory where you want the project to reside, go into that directory and issue the import command like this:

C:\>mkdir indyjug

C:\>cd indyjug

C:\INDYJUG>cvs import -m"Initial import" indyjug indyjug start

No conflicts created by this import

Here is the format for the import command:

cvs import [-m"comment"] repository-directory vendor-tag release-tag

If the comment parameter is not specified, CVS will prompt the user for one.  The repository-directory is the location where the module will reside in the repository, indyjug in this case.  The vendor-tag and release-tag parameters are required but are not currently used in CVS.

Once the module has been added, you need to get out and delete the working directory, and then check it out in order to use it.

C:\INDYJUG>cd ..

C:\>rmdir indyjug

checkout

The top-level projects within a repository are called modules, and a module must be checked out first in order to work on it.  Here's an example:

C:\>cvs checkout indyjug
cvs server: Updating indyjug

The checkout command will create a directory with the same name as the module underneath the current directory.  All the subdirectories and files in the module will be recursively copied to the client machine in a working directory so the developer can work on the code.

add

When a new file or directory needs to be added to the repository, the CVS add command is used.  The file is not actually placed in the repository until the user commits the file (see below).  Example:

C:\INDYJUG>cvs add Hello.java
cvs server: scheduling file `Hello.java' for addition
cvs server: use 'cvs commit' to add this file permanently

commit

Once the developer is satisfied with the current changes, the CVS commit command must be issued.  The commit command is also used to add new files to the repository.  CVS will prompt the user for a comment, or one can be passed in through the command line with the -m option.  Example:

C:\INDYJUG>cvs commit -m"Initial import" Hello.java
RCS file: C:/CVSROOT/indyjug/Hello.java,v
done
Checking in Hello.java;
C:/CVSROOT/indyjug/Hello.java,v  <--  Hello.java
initial revision: 1.1
done

diff

The CVS diff command is used to see all the differences between different file revisions, including a developer's working copy.  For instance, if the StringTest.java file has been modified, to see those differences try this:

C:\INDYJUG>cvs diff Hello.java
Index: Hello.java
===================================================================
RCS file: C:/CVSROOT/indyjug/Hello.java,v
retrieving revision 1.1
diff -r1.1 Hello.java
2c2
<   private static final String HELLO = "Helo IndyJUG!";
---
>   private static final String HELLO = "Hello IndyJUG!";

The diff command will show each line that has changed from the latest revision in the repository.  Differences between individual revisions viewed like this:

C:\INDYJUG>cvs diff -r 1.1 -r 1.3 Hello.java
Index: Hello.java
===================================================================
RCS file: C:/CVSROOT/indyjug/Hello.java,v
retrieving revision 1.1
retrieving revision 1.3
diff -r1.1 -r1.3
0a1,4
> /*
>  * $Id: Hello.java,v 1.3 2001/11/28 15:23:39 bonhamcm Exp $
>  */
>
2c6
<   private static final String HELLO = "Helo IndyJUG!";
---
>   private static final String HELLO = "Hello IndyJUG!";

log

To see the history of a file including all revisions, their authors and comments, use the CVS log command.  Example:

C:\INDYJUG>cvs log Hello.java

RCS file: C:/CVSROOT/indyjug/Hello.java,v
Working file: Hello.java
head: 1.3
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 3;     selected revisions: 3
description:
----------------------------
revision 1.3
date: 2001/11/28 15:23:39;  author: bonhamcm;  state: Exp;  lines: +4 -0
Added $Id$ tag
----------------------------
revision 1.2
date: 2001/11/28 15:21:20;  author: bonhamcm;  state: Exp;  lines: +1 -1
Fixed hello string
----------------------------
revision 1.1
date: 2001/11/28 15:19:33;  author: bonhamcm;  state: Exp;
Initial import
=============================================================================

status

C:\INDYJUG>cvs status
cvs server: Examining .
===================================================================
File: Hello.java        Status: Locally Modified

   Working revision:    1.3
   Repository revision: 1.3     C:/CVSROOT/indyjug/Hello.java,v
   Sticky Tag:          (none)
   Sticky Date:         (none)
   Sticky Options:      (none)