CVS is a heavily used source control system both in open source projects and commercial projects. This article explains frequently used commands by a developer.

Set the command-line environment

Firstly, before using cvs command, the CVSROOT environment variable should be set to point to CVS server. This command can be placed in ~/.bashrc to make it as default environment.

[neo@techpulp ~]# export CVSROOT=:pserver:neo@cvs.techpulp.com:/cvsroot

In the above command, cvs.techpulp.com is the CVS server, neo is the user name on the CVS server and /cvsroot is the base of the CVS repository in the server.

It is not necessary that CVS must be used only with remote CVS server. If you want to keep the CVS repository in the same system you are working on, you can use a local directory as a CVS repository. In such case, theĀ  CVSROOT environment variable must point to local repository as shown below.

[neo@techpulp ~]# export CVSROOT=/cvsroot

Logging in

Once the CVSROOT environment variable is set, you need to first login to CVS server to do any operations like import, check out or check in etc.

[neo@techpulp ~]# cvs login
Password:
[neo@techpulp ~]#

Checking out a project

The following command checks out the sources of myproject directory present in /cvsroot in the server. Effectively this checks out the latest sources of /cvsroot/myproject directory.

[neo@techpulp ~]# cvs co myproject

CVS can maintain multiple streams of a project using the concept of branching. For example, if one project is completed and release 1.0 is made. A new branch can be created for 1.0 release so that any maintenance releases can made from it while the main branch can be used for development of next major version 2.0. Checking out sources from a specific branch requires branch name to be given with “-r” option as shown below. The following command gets the source code from the branch named branch-1.

[neo@techpulp ~]# cvs co -r branch-1 myproject

Adding new files and directories

One can add new files and directories using “cvs add” command. But user must have something already checked out to do this. In other words, user can add new files or directories only with in a checked out project. The quickest way to check is to look for the presence of a directory named “CVS” in the directory where you one wants to add new files or directories. This operation only informs CVS server about new files and directories and you still need to check in all the files using “cvs ci“. The list of files and directories should be specified along with “cvs add” command as shown below.

[neo@techpulp myproject]# cvs add newfiles.txt newdir1/
A newfiles.txt
A newdir1
A newdir1/otherfile.txt
[neo@techpulp myproject]#

Removing files

One can remove files from CVS repository using “cvs rm” command. A directory cannot be removed but it can made empty by removing all files in it. You need to delete the files locally before running “cvs rm” command. This operation informs CVS server about the removal of a file but it still requires a check in operation to complete it.

[neo@techpulp myproject]# rm -f file3.txt otherdir1/file9.txt
[neo@techpulp myproject]# cvs rm file3.txt otherdir1/file9.txt
D file3.txt
D otherdir1/file9.txt
[neo@techpulp myproject]#

Checking in files

After making changes to existing files, adding new files using “cvs add” command and removing unwanted files using “cvs rm” command, a complete check in of sources can be done using “cvs ci” command without any arguments from the top level directory of the project. This command can be run individually on each modified file or in a directory.

[neo@techpulp myproject]# cvs ci

You can also check in files selectively using “cvs ci” command by specifying the files and directories. In case of a directory, CVS searches for all modified files recursively and does check in.

[neo@techpulp myproject/otherdir1]# cvs ci file20.txt