CVS Demystified

CVS stands for Concurrent Versioning System, it is most useful when there is a team of developers working on the project. cvs keeps track of all changes to the source tree and logs each operation, so at any point you can revert to an earlier version. It is also a useful backup tool if it is being used on a project that involves only one developer.

I am going to assume that the reader has a working knowledge of basic unix commands and already has cvs installed. IF at any point you need more information about a command type 'man <command>' and the command prompt. This also holds true for cvs itself.

Setting up a repository

CVS stores all of the files in a repository, and before you can actually use cvs you must setup a repository. The best way, and usually the easiest is to create a directory in your home call 'repository'. I usually make this directory a hidden file, ex '.repositry'.

Now that you have the repositry, you need to tell cvs where to find it. THe easiest way is to setup an environment variable called CVSROOT, or by specifying it on the commandline with the -d option. How you set the environment variable depends on the shell that you are using, type 'echo $SHELL' to determine which you are using.

	csh: setenv CVSROOT /home/joeuser/.repository
	bash: export CVSROOT=/home/joeuser/.repository
	commandline: cvs -d /home/joeuser/.repository

If you are using csh/tcsh you can add the above line to your .cshrc file. If you are using bash add the above code to your .bash_profile.

The next step is to initialize the repository with the default cvs files. The cvs program has an init command that automatically creates the default setup for you.

	cvs [-d <CVSROOT>] init

Congratulations the cvs repository is ready to use!

Using CVS

There are really only a few basic commands you need to know to use cvs, these are import, checkout, commit, update, release and log.

import

The import command is used to import a source tree into the repository. You should use add to add files to an existing source tree, but you must use import to import a new source tree. On the commandline you must specify the source tree name, vendor tag and the release tag. The only really important option is the source tree name, this is the name that you will use to reference this tree in your repository. The vendor tag and release tag are only really usefull if you are in a professional situation, but you must specify them anyways. It is best to just use some useful information such as the programmer and the current date. Once you run the cvs import command it will import all files in the current directory and it will recurse through directories.

	cvs [-d <CVSROOT>] import <source tree> <vendor tag> <release tag> 
								

Once you have successfully imported a source tree cvs will prompt you to add a message describing your actions. It is generally useful to enter meaningful information here incase you need to revert to a previous version and you need to see what changes were made. Once you enter the message you will see the ouput from the import, see the example below.

The files to import:
	[vfilby@mk2 ~/demo]$ ls
	demo.c  demo.h


The import command:
	[vfilby@mk2 ~/demo]$ cvs import demo vince june

Adding a meaning message to the cvs operation:
	Added the demo source tree.

	CVS: ----------------------------------------------------------------------
	CVS: Enter Log.  Lines beginning with `CVS:' are removed automatically
	CVS:
	CVS: ----------------------------------------------------------------------


Output from the import:
	N demo/demo.h
	N demo/demo.c

	No conflicts created by this import

	[vfilby@mk2 ~/demo]$
								

*** Note: The default editor in most shells is vi, and cvs will use vi to enter log messages. Either change your default editor through a shell environment variable or learn basic vi, which you should probably know anyways.


checkout

The checkout command is used to get a copy of the source tree from the repository.

[vfilby@mk2 ~/tmp]$ cvs checkout demo
cvs checkout: Updating demo
U demo/demo.c
U demo/demo.h
[vfilby@mk2 ~/tmp]$ ls
demo
[vfilby@mk2 ~/tmp]$ cd demo
[vfilby@mk2 demo]$ ls
CVS  demo.c  demo.h
[vfilby@mk2 demo]$
								
update

This command syncronizes your current source to the source tree in the repository. In the example below I added a file to the repository and ran update. M means that your copy of the file is modified, U means that the file was added.

[vfilby@mk2 ~/tmp]$ cvs update demo
cvs update: Updating demo
M demo/demo.c
U demo/main.c
								
commit

This command commits all changes made to the source tree in the repository. This is the "dangerous" cvs command in the respect that you shouldn't just haphazardly commit changes. It is usually a good practise to only commit have you have made a change _and_ debugged the change. IT usually isn't good practise to commit code that doesn't work.

The command:	
	[vfilby@mk2 ~/tmp]$ cvs commit demo

Adding a meaningful log message:	
	Added commandline functionality.

	CVS: ----------------------------------------------------------------------
	CVS: Enter Log.  Lines beginning with `CVS:' are removed automatically
	CVS:
	CVS: Committing in demo
	CVS:
	CVS: Modified Files:
	CVS:  demo.c
	CVS: ----------------------------------------------------------------------

Output from the commit operation:
	Checking in demo/demo.c;
	/home/vfilby/.repository/demo/demo.c,v  <--  demo.c
	new revision: 1.3; previous revision: 1.2
	done
	[vfilby@mk2 ~/tmp]$
							
release

This command releases your copy of the source tree from the cvs server. NOTE: After you do this the cvs server does not know that you have a copy of the source, so often it is a good idea to use the [-d] option to release and delete.

[vfilby@mk2 ~/tmp]$ cvs release -d demo
M demo.h
You have [1] altered files in this repository.
Are you sure you want to release (and delete) directory 'demo': y
 							
log

This command is used for viewing the logs on a file. IF you used meaning full llog messages they will be very handy right now! You can use just cvs log to get the logs on every file in the repository or you can specify the filename for the log that you are requesting.

[vfilby@mk2 demo]$ cvs log demo.h

RCS file: /home/vfilby/.repository/demo/demo.h,v
Working file: demo.h
head: 1.1
branch: 1.1.1
locks: strict
access list:
symbolic names:
        june: 1.1.1.1
        vince: 1.1.1
keyword substitution: kv
total revisions: 2;     selected revisions: 2
description:
----------------------------
revision 1.1
date: 2000/06/22 13:31:22;  author: vfilby;  state: Exp;
branches:  1.1.1;
Initial revision
----------------------------
revision 1.1.1.1
date: 2000/06/22 13:31:22;  author: vfilby;  state: Exp;  lines: +0 -0
Added the demo source tree.


=============================================================================
[vfilby@mk2 demo]$
							

Using Pserver

Standard cvs is only local to the machine that the repository is stored on. Often times multiple group members are working on the same thing at the same time, so we need a method to access cvs remotely. The most common way to do this is to use pserver. Before you can use pserver you will have to ask your administrator to enable it, and to allow pserver to access your repository or set it up yourself (if you are root).

To run pserver you need to be root. Add a line similar to the following to /etc/inetd.conf to enable pserver to start at boot. To start pserver independantly just run 'cvs [--allow-root <CVSROOT>] pserver'. You can have as many --allow-root options as you like.

# CVS SERVER
cvspserver  stream  tcp nowait  root    /usr/bin/cvs cvs  \
				--allow-root=/home/joeuser/repository pserver
							

Once pserver is setup it is almost identical to using cvs localy. The main differences are that you have to use a different CVSROOT and you have to login.

To access your repository you must change you CVSROOT to point to the machine that hosts your repository. To do this change your CVSROOT environment variable so that it looks like the one in the example below, except change the machine name, user name and repository to the match yours. After that is done, use the cvs login operation and enter your password (more then likely the same you use to telnet or ssh to the machine) and you can use cvs as if you were running locally.

set CVSROOT = :pserver:joeuser@mydom.org:/path/to/the/repository
cvs login
							

Satus Codes

CVS uses one digit status codes and is usually in the form of a letter a space and the filename. You can see the them in the above examples.

From more detailed information on the status codes for different commands see the cvs man page or the online FAQ's.

More Information

  1. Sourcegears's CVS documentation
  2. Pascal Molli's CVS website
  3. GNU Online Documentation for CVS

Post new comment

The content of this field is kept private and will not be shown publicly.