Your are the 9347 unique visistor since Nov. 10, 2004
CVS in 60 Seconds
A CVS Tutorial

Links

Creating the cvs repository

The first step is to create the cvs repository (also known as a tree).

  • create an empty directory which will hold the tree.
    mkdir ~/mycvsroot
  • Set the CVSROOT environment variable.
    setenv CVSROOT ~/mycvsroot
  • Create the repository:
    cvs init
  • If you now look in ~/mycvsroot, you'll find the basic files which constitute a repository.

Adding your project to the repository

If the files you want to install in CVS reside in `wdir', and you want them to appear in the repository as `$CVSROOT/myproject', you can do this:

$ cd wdir
$ cvs import -m "Imported sources" myproject MyBrand start

Unless you supply a log message with the `-m' flag, CVS starts an editor and prompts for a message. The string `MyBrand' is a vendor tag, and `start' is a release tag. They may fill no purpose in this context, but since CVS requires them they must be present.

You can now verify that it worked, and remove your original source directory.

$ cd ..
$ cvs checkout myproject
$ diff -r wdir myproject
$ rm -r wdir

Erasing the original sources is a good idea, to make sure that you do not accidentally edit them in wdir, bypassing CVS. Of course, it would be wise to make sure that you have a backup of the sources before you remove them.

 

Checking out the project

You can get "myproject" files from your CVS repository by following commands:

$cvs co myproject
or
$ cvs checkout myproject

A subdirectory named as "myproject" will be created under current directory. If you want the files to be placed into the current directory and you don't want cvs to create a subdirectory, try this instead:

cvs co -d . myproject

Remote project checkout example: supposing you want to access the module `foo' in the repository `/usr/local/cvsroot/', on machine `faun.example.org', you are ready to go: (make sure to use absolute path, eg. /usr/...)

 cvs -d :ext:myusername@faun.example.org:/usr/local/cvsroot checkout foo

 

Checking out a single file

If youi want to get a single file "testFile" from the repository, you do it like this:

$cvs co myproject/testFile

If you want a particular revision of that file:

$cvs co -r1.1 myproject/testFile

That will give you revision 1.1 of that file.

Perhaps the file lives in a subdirectory of the project. No problem. Just supply the pathname

$cvs co myproject/path/to/thefile/testFile

 

Checking things back in

Once you are happy with any changes you have made, you can commit these changes to the repository by doing this:

$ cvs commit -m "Added an optimization heap in FisrtPass.java"

`-m' flag used to avoid starting an editor. You can specify the log message on the command line as above. I much prefer this way. You'd better know how to use "vi" if you commit without "-m" flag. :-)

check back a single file by doing this:

$ cvs commit -m "Added an optimization heap in FisrtPass.java" FirstPass.java

 

Adding new files to the repository

If a new file is needed, you can add it to the repository by doing this:

$ cvs add mynewscript.pl
cvs add: scheduling file 'mynewscript.pl' for adding it

On your next commit, the file will be added to the repository.

 

Removing files from the repository

If a file is not needed, you can remove it from the repository by doing this:

$ cvs remove mynewscript.pl
cvs add: scheduling file 'mynewscript.pl' for removing it

On your next commit, the file will be removed from the repository.

Here is an example of removing several files:


$ cd test
$ rm *.c
$ cvs remove
cvs remove: Removing .
cvs remove: scheduling a.c for removal
cvs remove: scheduling b.c for removal
cvs remove: use 'cvs commit' to remove these files permanently
$ cvs ci -m "Removed unneeded files"
cvs commit: Examining .
cvs commit: Committing .

If you execute remove for a file, and then change your mind before you commit,
you can undo the remove with an add command.


$ ls
CVS   ja.h  oj.c
$ rm oj.c
$ cvs remove oj.c
cvs remove: scheduling oj.c for removal
cvs remove: use 'cvs commit' to remove this file permanently
$ cvs add oj.c
U oj.c
cvs add: oj.c, version 1.1.1.1, resurrected

If you realize your mistake before you run the remove command
you can use update to resurrect the file:


$ rm oj.c
$ cvs update oj.c
cvs update: warning: oj.c was lost
U oj.c

 

Removing directories

In concept removing directories is somewhat similar to removing files--you want the directory to not exist in your current working directories, but you also want to be able to retrieve old releases in which the directory existed.

The way that you remove a directory is to remove all the files in it. You don't remove the directory itself; there is no way to do that. Instead you specify the `-P' option to cvs update or cvs checkout, which will cause CVS to remove empty directories from working directories. (Note that cvs export always removes empty directories.) Probably the best way to do this is to always specify `-P'; if you want an empty directory then put a dummy file (for example `.keepme') in it to prevent `-P' from removing it.

Note that `-P' is implied by the `-r' or `-D' options of checkout. This way CVS will be able to correctly create the directory or not depending on whether the particular version you are checking out contains any files in that directory.

 

Rename files or directory

 The Normal way to Rename

The normal way to move a file is to copy old to new,
and then issue the normal CVS commands to remove old
from the repository, and add new to it.


$ mv old new
$ cvs remove old
$ cvs add new
$ cvs commit -m "Renamed old to new" old new

This is the simplest way to move a file, it is not error-prone,
and it preserves the history of what was done. Note that to access
the history of the file you must specify the old or the new name,
depending on what portion of the history you are accessing.
For example, cvs log old will give the log up until the time of the rename.
      

 

cvs commit: Up-to-date check failed for `about.html'

Sometimes, when you try to commit stuff back to the database, things don't go as planned. For example:

$ cvs commit
cvs commit: Examining .
cvs commit: Up-to-date check failed for 'about.html'
cvs commit: Examining _private
cvs commit: Examining graphics
cvs commit: Examining images
cvs commit: Examining scripts
cvs [commit aborted]: correct above errors first!

It was suggested to me that about.html was older than that which was in the repository and that I should try this instead:

$ cvs update about.html
RCS file: /home/dan/mycvs/freshports/about.html,v
retrieving revision 1.1.1.1
retrieving revision 1.2 Merging differences between 1.1.1.1 and 1.2 into about.html
about.html already contains the differences between 1.1.1.1 and 1.2

 

other useful options

  • $cvs status
  • $cvs log (to see history logs)
  • $cvs diff
  • $cvs diff version_number myfile.java
  • $cvs history (options -e, -c etc.)

 

Web Resources

http://ccvs.cvshome.org/servlets/ProjectHome

Linux CVS HOW-To & CVS vs. RCS

 

CVS for Windows

CVSNT a multi-platform CVS server engine

WinCVS A set of GUI front-end for CVS written in C++