LINUX GAZETTE

[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]

"Linux Gazette...making Linux just a little more fun!"


CVS: Concurrent Versions System

A source control program used by Mark

By Mark Nielsen


  1. References
  2. Introduction
  3. Upload files to the CVS repository-- creating your first repository.
  4. Download files from CVS.
  5. Adding a file to the cvs repository "My_Files"
  6. Deleting a file from the cvs repository "My_Files"
  7. Changing a file and uploading changes to the repository "My_Files"
  8. Conclusion

References

  1. www.cyclic.com
  2. Manual for CVS
  3. New user information.
  4. Support ----- I am not sure if this link is valid. There seems to be a company which will support CVS.

Introduction

CVS is a cool program to let people control different version of their software. It has saved my butt before. It is relatively easy to use, and everybody who is either new to programming, or who wants to stick to free software, should use CVS. Recently, CVS has become officially supported by a company.

Getting Started

First off, I assume you are using the BASH shell, which is standard on most intelligent Unix systems. I also assume you have root access to the computer you are using. There are simple ways to let various people have access to a CVS repository, but I will assume it will only be used by one person for now.

Login as root, and execute the following. I assume you are the user "mark", but it can be any user on your system.
mkdir /usr/local/cvs
chown mark /usr/local/cvs

Now login as "mark" and do the following.

Edit your .bashrc file using vi or emacs or even pico, and enter these commands.
CVSROOT=/usr/local/cvs
export CVSROOT

Save it and then execute "source .bashrc". Now when you log in, it will setup your environment to use this directory by default if you don't specify a directory to use.

Make a directory, which is need for cvs.
mkdir /usr/local/cvs/CVSROOT

Upload files to the CVS repository

The purpose of this exercise is to upload files into the repository so that the files are under source control. Later, we will download the files into another directory, or the Working directory.

In your home directory for "mark", make a directory called "Temp_Source" and put a few files in it. Such as,
mkdir Temp_Source
ls > Temp_Source/File1.txt
ls Temp_Source/* > Temp_Source/File2.txt

Now we want to put the files in Temp_Source into CVS. Do this, enter the directory Temp_Source.
cd Temp_Source
then issue this command
cvs import -m "Test Import" My_Files Revision1 start

Now we are ready to make a working directory. We will forget about the directory Temp_Source and pretend it never existed. By the way, take a look at /usr/local/cvs and see what cvs has done to it. You can add more packages to the cvs repository if you wish.

Download files from CVS

Okay, now we want to download these files into a Working directory and we will pretend that our Temp_Source directory doesn't exist. This will often be the case where someone else enters files into CVS and expects you to maintain them.

When we checkout a package from cvs, it will create a directory for us. The parameter "My_Files" that we specified when we uploaded the files into cvs will be the name of the directory created for us when cvs downloads the package for us.

Now we need to get the cvs package.
cvs checkout My_Files

If we look, we now have a directory named "My_Files". Enter into the directory,
cd My_Files
and execute the the "ls" command.
ls
 

Adding a file to the cvs repository "My_Files"

I assume you are in the directory My_Files. In order to add a file to the repository, create one.
ls /etc > File3.txt
Now execute the command to set it up so that the file will be added to the cvs repository.
cvs add File3.txt
Now you need to actually upload the file. The previous command just setup the configuration to do it.
cvs commit

"cvs commit" will bring you into your default editor, vi or emacs or something else. Save the file, and when you quit the editor, cvs will ask you to continue, and select the option to continue. Now you have uploaded a file to the cvs repository "My_Files".

Also, execute the "ls" command, and you will notice that you have a directory called "CVS". cvs creates a directory "CVS" in every directory that you download files from a repository and it keeps the changes up to date.
 

Deleting a file to the cvs repository "My_Files"

In order to delete a file from the cvs repository, do this
rm File3.txt
cvs remove File3.txt
cvs commit

The first step actually deletes the file in your directory. The second step removes it from the configuration of the current directory you are in. The third step commits this change to the cvs repository"My_Files". If you do not execute "cvs remove File3.txt", you will find it hard to execute "cvs commit" in the future and it won't update the repository correctly, at least that has been from my experience.

Changing a file to the cvs repository "My_Files"

I assume you are in the directory "My_Files". Let us add some content to the file File2.txt.

ls /var >> File2.txt
cvs commit
 

Downloading updates that other people make

If you have downloaded a package from a repository that someone else is maintaining, if you wish to download all the changes, then execute the followign command,

cvs update -dP

The "d" creates any directories that are or are missing.
The "P" removes any directories that were deleted from the repository.
 

Comments

I have noticed the the "cvs commit" command should recursively go through all directories from where you are currently at and list all the changes in one file. However, on some systems, it makes a one file per directory, which means right before it uploads the changes to the repository, cvs starts the editor for each directory that has changes, which is annoying. I have to figure out how to set it up to list all the changes in one file and not many.

CVS is the best source control program I have used. It is the best because it comes by default on major Linux distributions, and it is relatively easy to use, unlike some other source control software I have seen. Major free software websites use CVS, which is another plus, because if they use it, then it will be an ongoing project. Also, you can download documents using cvs over the internet. I downloaded all the sgml howtos from the Linux Documentation Project using cvs using their anonymous CVS server. This is very useful if you want to keep yourself up to date on various versions of documentation.


Mark works as a computer guy at The Computer Underground and also at ZING and also at GNUJobs.com (soon).


Copyright © 2000, Mark Nielsen
Published in Issue 57 of Linux Gazette, September 2000

[ Prev ][ Table of Contents ][ Front Page ][ Talkback ][ FAQ ][ Next ]