CVS (Concurrent Versions System) Notes

What follows are some practical notes for how to use CVS, especially in CSE courses. To read more about CVS and learn more tricks see some of these web sites and also see the man page for cvs (% man cvs).

How to set up a CVS repository (one-time setup)

  1. Set CVSROOT environment variable to the path where the repository will be located. You will probably want to put this line in your shell's startup file (eg. ~/.bashrc). (NOTE: make sure that the Repository directory doesn't already exist, it will be created by init in step 2.)
        % export CVSROOT=~/CVSRepository
  2. Initialize the repository (this is only done one time; you should not have to do this again all quarter)
        % cvs init 
    (NOTE: notice that the directory ~/CVSRepository now exists)

How to set up a new Module (Programming Assignment) in the repository and start using CVS

  1. First create the programming assignment directory
        % cd
    % mkdir A1
  2. Change directory (cd) into the new empty PA directory and import the directory into CVS creating a new Module
        % cd A1
    % cvs import -m "Setting up A1 module - first import" A1 vtag rtag
    -m option specifies a log message
    vtag is the vendor tag (we won't be using this but this argument is required). Just use "vtag".
    rtag is the release tag (we won't be using this but this argument is required). Just use "rtag".

  3. cd back out of the new empty PA directory and remove it
        % cd
    % rmdir A1
  4. Now check out a working copy of the Module (programming assignment)
        % cvs checkout A1

    At this point you have set up and checked out a working version of your programming assignment. You only need to do these steps 1 - 4 once each time you start a new programming assignment. The rest of these steps (5 - 7) are what you would normally do every time you come in to work on your programming assignment.


  5. And now you are ready to go work in the Module
        % cd A1
    % vi A1.java ... etc.
  6. Once you have created a new file and you want to add that new file to the repository for that module
        % cvs add file
    You can also use the *.java wildcard to match all the .java files in your directory
        % cvs add *.java
  7. When you are finished editing a file (or group of files), you want to commit those changes to the repository.
        % cvs commit file
    This will bring up an editor session for you to edit a log message about the changes you made to this file since the last commit. This is just a log message for you or anyone else looking at the logs to get a high-level idea of what changes were made. You can specify the log message in the commit command using the -m option.
        % cvs commit -m "Your log message" file
    If you have several files you want to commit at the same time with the same log message, just don't specify the filename. Only those files that have changed since the last commit on them will be updated/logged in the repository
        % cvs commit -m "Common log message for all files being committed"
You want to do a commit whenever you want to be able to retrieve a snapshot of the state (revision) of your file(s).

The normal cycle once you have set up and checked out your module is 5, 6, and 7 above -- edit, add (for new files), commit cycle.


How to retrieve a previously committed version of a file

  1. You blew it somehow and need to get a previously saved/committed version of a file. If you want the last committed/saved version
        % cvs update -p file > file
    NOTE: Be sure to use the -p option.

    If you need a different version saved with an earlier commit, use cvs diff or cvs log to determine which revision number you want to retrieve. Let's say you want revision 1.4 in this example

        % cvs update -r 1.4 -p file > file
    NOTE: Be sure to use the -p option.

    Now your working version of the file has been replaced with whatever version you specified. Go ahead and edit and commit when you are ready to commit your changes to create a new revision of this file.


How to put a Module (an existing project) in the repository

Do this only if you already have a bunch of files in a project directory and you forgot to set up the project directory as a module in CVS before working in that directory.
  1. First move into a currently active directory for which you wish to make a new CVS Module
        % cd MyProjDir

  2. Now import the directory into CVS and create a module. (NOTE: this is done within the directory you want to be archived)
        % cvs import -m "First import" MyProjDir tag1 tag2
    N MyProjDir/log.txt
    N MyProjDir/Main.java

    No conflicts created by this import

    -m "First Import": specifies log message
    MyProjDir: specifies name of Module
    tag1 and tag2: logical tags which I never use

    (NOTE: If -m isn't used on the command line then vi will start so that you can edit a log message. To start typing press 'a' or 'i'. To finish and save the message go to escape mode by pressing ESC and then type ':wq'. You can use a different editor by using the -e option for cvs)
           -e editor
    Use editor to enter revision log information.
    Overrides the setting of the CVSEDITOR and the EDI�
    TOR environment variables.

  3. Backup original directory: You will no longer be working in the original directory MyProjDir. Instead you will be checking out a working version of that directory from the repository (which could have the same name). I suggest moving the original directory so that you have a last ditch backup.
        % cd
    % mv MyProjDir MyProjDir.bak
  4. Now check out the module to create a working directory of this module
        % cvs checkout MyProjDir
    % cd MyProjDir
    And off you go into the edit, add (for new files), commit cycle.

Special thanks to Paul Kube, Michele Strout and Adam Barna and Rick Ord for their help with these notes.
These notes were adopted from Michele's CVS Notes