4.1. Concurrent Versions System (CVS)

Table of Contents

4.1.1. Terminology
4.1.2. Configuration
4.1.3. Setup
4.1.4. Updating your workspace
4.1.5. Restoring a Previous Version
4.1.6. Branches
4.1.7. Publishing a project
4.1.8. References
The Concurrent Versions System (CVS) is an open-source tool for source code maintenance.

4.1.1. Terminology

repository
Location where CVS keeps master copies of all files it knows about, along with histories for those files.
project
Collection of files that belong together, e.g. a program or library.
checkout
Make a local copy of the files to allow you to make and test changes locally (without affecting what others see).
commit
Save your changes back to the repository, where they are available to other users of the repository (also allows you to roll back to a previous version).

4.1.2. Configuration

First, configure your environment (we will assume csh/tcsh). To set the editor that will be used to create CVS log messages:

$ setenv CVSEDITOR vi
To enable ssh for remote transfers:
$ setenv CVS_RSH ssh
You may optionally set a default repository. To set a local repository as the default:
$ setenv CVSROOT "/home/userid/cvs"
To set a remote repository as the default:
$ setenv CVSROOT ":ext:userid@cvs.cs.clemson.edu:/home/userid/cvs"

Note: For the remainder of this section, it is assumed that you have the CVSROOT environment variable set. If you choose not to set this variable, please replace 'cvs' with 'cvs -d /home/userid/cvs' for the remainder of this tutorial.

4.1.3. Setup

First, initialize the repository:

$ cvs init
Next, create the initial project (skip if project exists):
$ cd /home/userid
$ mkdir cpscXXX
$ cd cpscXXX
$ mkdir lab1
$ touch lab1/Makefile
$ mkdir lab2
Now we are ready to import the project:
$ cvs import -m "Importing project cpscXXX for userid" cpscXXX userid start
cvs import: Importing /home/userid/cvs/cpscXXX/lab1
N cpscXXX/lab1/Makefile
N cpscXXX/lab1/main.c
cvs import: Importing /home/userid/cvs/cpscXXX/lab2

No conflicts created by this import
You may now safely delete/move the original project directory, because the project can be checked out from CVS:
$ cd /home/userid
$ rm -fr cpscXXX
$ cvs checkout cpscXXX
cvs checkout: Updating cpscXXX
cvs checkout: Updating cpscXXX/lab1
U cpscXXX/lab1/Makefile
U cpscXXX/lab1/main.c
cvs checkout: Updating cpscXXX/lab2
$ cd cpscXXX

Note: You may import an unrestricted number of projects into a repository.

Now that our project has been check out, we are free to make changes to it. Once you have made your changes, you must commit them to the repository. Each time you commit to the repository, CVS will prompt you to enter a log message that describes the changes. You may supply the message using the -m flag; if you do not supply a message at the command line, CVS will open an instance of CVSEDITOR. To commit a change:

$ cvs commit -m "Changed stuff"
cvs commit: Examining .
cvs commit: Examining lab1
cvs commit: Examining lab2
Checking in lab1/Makefile;
/home/userid/cvs/cpscXXX/lab1/Makefile,v  <--  Makefile
new revision: 1.2; previous revision: 1.1
done

Eventually, you will want to add files to your project:

$ cd /home/userid/cpscXXX/lab1
$ touch draw.c
$ cvs add draw.c
cvs add: scheduling file `draw.c' for addition
cvs add: use 'cvs commit' to add this file permanently
$ cvs commit -m "Added draw.c"
cvs commit: Examining .
RCS file: /home/userid/cvs/cpscXXX/lab1/draw.c,v
done
Checking in draw.c;
/home/userid/cvs/cpscXXX/lab1/draw.c,v  <--  draw.c
initial revision: 1.1
done
You will likely want to remove files as well:
$ cd /home/userid/cpscXXX/lab1
$ rm main.c
$ cvs remove main.c
cvs remove: scheduling `main.c' for removal
cvs remove: use 'cvs commit' to remove this file permanently
$ cvs commit -m "Removed main.c"
cvs commit: Examining .
Removing main.c;
/home/nkraft/cvs/cpscXXX/lab1/main.c,v  <--  main.c
new revision: delete; previous revision: 1.1.1.1
done

4.1.4. Updating your workspace

Before you commit your changes, you'll need to have the latest version of the project. If other users are simultaneously updating your project, you must keep your local version in sync with the repository. To update your workspace:

$ cd /home/userid/cpscXXX/lab1
$ cvs update
cvs update: Updating .
U Makefile

4.1.5. Restoring a Previous Version

To restore a project to its state at a given date and time in the past, use the -D flag:

$ cd /home/userid/tmp
$ cvs checkout -D "2006-04-20 16:20" cpscXXX
cvs checkout: Updating cpscXXX
...

4.1.6. Branches

Branches allow you to maintain seperate versions of a projects, e.g. a stable version, a testing version, and an unstable version. You create branches with the -b flag:

$ cd /home/userid/cpscXXX
$ cvs tab -b stable
cvs tag: Tagging .
cvs tag: Tagging lab1
T lab1/Makefile
T lab1/draw.c
cvs tag: Tagging lab2
After tagging the project, you must release the current working directory and checkout a fresh copy of the project (now specifying the branch name):
$ cd /home/userid
$ cvs release -d cpscXXX
You have [0] altered files in this repository.
Are you sure you want to release (and delete) directory `cpscXXX': y
$ cvs checkout -r stable cpscXXX
cvs checkout: Updating cpscXXX
cvs checkout: Updating cpscXXX/lab1
U cpscXXX/lab1/Makefile
U cpscXXX/lab1/draw.c
cvs checkout: Updating cpscXXX/lab2

4.1.7. Publishing a project

To do its job, CVS adds many auxilary files to your workspace. To obtain a copy of the project without these added files:

$ cd /home/userid/public_html
$ cvs export -D "now" cpscXXX
cvs export: Updating cpscXXX
cvs export: Updating cpscXXX/lab1
U cpscXXX/lab1/Makefile
U cpscXXX/lab1/draw.c
cvs export: Updating cpscXXX/lab2

4.1.8. References

http://cvsbook.red-bean.com/cvsbook.html