Introduction to CVS

CS230/330 - Operating Systems (Spring 1999).

Overview

CVS is version control system that is particularly useful when working on large software projects or when working in groups. In a nutshell, CVS stores your software in a special repository. This repository holds all of the versions of your software as well as information about when files were modified, who modified them, and logs describing why changes were made. Some of the more notable features of CVS include the ability to "undo" changes if you mess up and making life easier when multiple people are working on a single project.

All of the gory details about CVS can be found at www.cyclic.com. Postscript documentation can also be found in the /usr/local/doc directory on cs230. This document describes the bare essentials that you need to know for this class.

The Repository

Your account on cs230 should already be properly configured to use CVS. In your home directory, there should be a directory called CVSROOT. This directory is the repository that will hold all of your files. Under normal circumstances, you should never have to look in this directory. Likewise, you should never modify any files found in this directory.

Creating a new CVS project

To create a new CVS project, first create a directory with all of your working files. For example, you might have a directory "myproject" that looks like this:
% cd myproject
% ls
Makefile
README
bar.c
foo.c
% 
Make sure your directory is clean and only contains the files you want to place in the repository. Object files, executables, core files, and editor backup files should be deleted from the directory in this process.

Now, import your directory into the CVS repository as follows:

% cd myproject
% cvs import myproject yourname start
N myproject/Makefile
N myproject/README
N myproject/bar.c
N myproject/foo.c

No conflicts created by this import
%
After typing the 'cvs import' command, an editor will appear asking you to type in a log message. This message should simply be a short description of the project. After saving the message, the files will be imported into the repository.

Note : To save the log message and exit from emacs, you will have to type Control-X Control-S followed by Control-X Control-C.

After importing a directory into CVS, you should either rename or remove the original project directory and checkout a fresh version from the repository.

Checking out a project

To check a project out of the CVS repository use the 'cvs checkout' command like this:
% cvs checkout myproject
cvs checkout: Updating myproject
U myproject/Makefile
U myproject/README
U myproject/bar.c
U myproject/foo.c
Now, all of your original files should be restored in a new directory "myproject".

Making changes

When working in a CVS project directory, you can modify all of the files exactly as you normally would. However, after you are satisfied with a set of changes, it is a good idea to commit those changes back to the repository. This can be done for individual files or for an entire directory using the 'cvs commit' command like this:
% cvs commit foo.c
Checking in foo.c;
/u1/dave/CVSROOT/myproject/foo.c,v  <--  foo.c
new revision: 1.2; previous revision: 1.1
done
%
Before committing the file, an editor will be started where you will be asked to enter a log message describing your changes. As a shortcut, you can also enter a change message on the command line like this:
% cvs commit -m "Fixed the segmentation fault error" foo.c
Changes made to an entire directory can be committed in the same manner. For example:
% cvs commit -m "Handin" myproject

Adding new files and directories

When you add new files and directories to your project, they are not automatically added to the CVS repository. Instead, you must explicitly add the files using the 'cvs add' command like this:
% cvs add spam.c
cvs add: scheduling file `spam.c' for addition
cvs add: use 'cvs commit' to add this file permanently
This only tells CVS that a new file will be added. The addition does not take effect until you commit changes using the 'cvs commit' command.

Removing files from the repository

To remove a file from the repository, use the 'cvs remove' command. For example:
% rm foo.c
% cvs remove foo.c
cvs remove: scheduling `foo.c' for removal
cvs remove: use 'cvs commit' to remove this file permanently
Again, this command only takes effect after you have committed your changes with the 'cvs commit' command.

Handing in a Project

All projects in this course will be handed in via CVS. Prior to handin, you need to go through the following checklist:

Where to go from here?

More information about CVS is available at www.cyclic.com. More details about each of the commands can be found by typing 'man cvs'.