CVS in 15 minutes*

This guide was prepared to give a quick overview of CVS and to provide a reference of basic commands which are frequently used. This guide was prepared using Derek Robert Price's exhaustive guide on CVShome. This short guide provides a quick introduction to CVS with instructions on how to create a repository, how to add a project, how to add files, how to check in and check out various versions and how to browse the log messages. This guide however doesn't go into the issues of how to setup a remote repository.

CVS - Concurrent Versions System

CVS is a version control system and is used to record the history of your source files. CVS provides an efficient way of storing different versions of the file you are working on by storing only the differences between the successive versions.

Repository

It is a place where all your files are stored. This is specified by the environment variable '$CVSROOT'. This variable can be set in your .cshrc file by the following command

    setenv CVSROOT /home/user_name/cvs_repository


where '/home/user_name/cvs_repository' is the directory where the files will be stored. To create repository, run 'cvs init'
prompt> cvs -d /home/user_name/cvs_repository init
'cvs init' doesn't overwrite on an existing repository. After this you will get the following directory structure

    /home
    |___  user
           |_____ cvs_repository
                         |________CVSROOT
                                     |
                                     |

Adding a Project

If you already have a directory tree which you want to add, lets say 'ver1' (incase you are building the repository for a new project, you can go ahead and make the directory tree and then follow the instructions in this section).  Let's say you want this project to appear in the repository as '$CVSROOT/work_repository/ver1', then you can do the following:

prompt>    cd ver1
prompt>    cvs import -m "New Sources" work_repository/ver1  vendor_tag  start

The option '-m' specifies that the user wants to supply a log message. If the message following '-m' option is not present then CVS prompts user to enter a message. After verifying that this worked, you can remove your original source directory.

prompt>     cd ..
prompt>     cvs checkout work_repository/ver1
prompt>     diff -r ver1 work_repository/ver1
prompt>     rm -r ver1                                    # This will remove your original sources


Getting the Source

To get the source you can specify the relative path of the directory (with respect to 'CVSROOT') which you want to check out. For this you can use the 'checkout' command

prompt>     cvs checkout test_rep/test1

here your sources are in '$CVSROOT/test_rep/test1'. You can also associate modules with directories, but I won't go into those details here. This will create a new directory tree
test_rep/test1 and put all the source files in this directory. This checked out directory will contain a directory called 'CVS' and normally you should not modify files in it.
prompt>     cd test_rep/test1
prompt> ls
CVS file1.pl file2.pl
After getting the source, you can make changes on any file, say file1.pl.

Committing your files

After making the changes in a file, you might want to make a new version (for example if you have made required changes and won't be making any changes today/near future). You can say
prompt>     cvs commit	file1.pl

on giving this command, CVS will start an editor and ask you to enter a log message. The default editor on unix machines is 'vi' you can change this by changing the environmnet variable  $CVSEDITOR in your '.cshrc'


Adding Files to a Directory

After creating a new directory (or in an already existing project) you might want to add new files to the directory. You can do this by following the steps given below

1. Get a working copy of the directory by checking it out -     prompt>     cvs checkout test_rep/test1
2. Create a new file inside your working directory
3. Use 'cvs add file3.pl' to tell CVS that you want to version control this file
4. Use 'cvs commit file1.pl' to actually commit the file to the repository

This command 'add' can also be used to add new directories. However this command is not recursive. In order to add 'level1/level2', you will first have to add 'level1' and then

prompt>    cd level1
prompt>     cvs add level2


Browsing Log Messages

A simple way to see the list of log commands is to use 'cvs log'




These basic set of commands should get you started to get more information or downloading CVS, please visit CVShome.


*Note: This guide is by no means exhaustive, it was developed to provide a quick reference of commands for using CVS. The  set of instructions provided here have been tested, but still if you are new to CVS, it will be a good idea to test these instructions on a dummy project and then proceed to implement on a live project. Even for a live project, it is good practise to take backup. The information provided here is as is and the author (Sarvesh Bhardwaj) takes no responsibility for any data loss of the user. I have followed the exhaustive guide by Derek Robert Price, if some content has copyright issues, kindly inform me and I will remove it.