CVS Home
CVS Home

Getting Started with CVS

Steps to Create a CVS Repository

Overview for Importing an Existing Tree Structure

Say you have an existing directory structure that you want to source control. These steps explain how to do it. The first thing you want to do is put the files in the structure that you would like to keep them in (files can be moved around later if necessary). Here's an example file structure:

    c:\WorkSpace\projectA
        readme.txt
        bin\script1.pl
        bin\script2.pl
        bin\shell1.sh
        bin\shell2.sh
        docs\index.html
        docs\help1.html
        docs\help2.html
    c:\WorkSpace\projectB
        info.txt
        docs\index.html
        docs\chapter1\help1.html
        docs\chapter1\help2.html
        docs\chapter2\help1.html
        docs\chapter2\help2.html
        docs\chapter3\help1.html
        files\script1.pl
        files\script2.pl
        files\shell1.sh
        files\shell2.sh
    c:\WorkSpace\projectC
        foo.pl
        test.pl

This example has files organized into three different projects. Each can exist in CVS separately and still be related.

Create the Repository

  1. First make the a directory for the repository:
    >mkdir c:\cvsroot\CVSROOT
  2. Set your CVSROOT env variable (put it in your .profile or .cshrc)
    CVSROOT=c:\cvsroot\CVSROOT; export CVSROOT

Import Existing files and directories

The following steps are based on the example shown above. This will add the files into the CVS repository under a new directory called projects. "projects" will be a new directory that you have all of your projects under. It will replace the "WorkSpace" directory that was used before.

  1. cd c:\WorkSpace\projectA
  2. cvs import -m "importing initial version of files" projects/projectA mycompany start
  3. cd c:\WorkSpace\projectB
  4. cvs import -m "importing initial version of files" projects/projectA mycompany start
  5. cd c:\WorkSpace\projectC
  6. cvs import -m "importing initial version of files" projects/projectA mycompany start

The files are directories are now all added into the repository.

Verifying that the repository was created

Before deleting your files, make sure the repository was created successfully. To do this, make a temporary directory somewhere and check out your source files.

cvs co projects

The output of this command will look something like this:

U projects/projectA/readme.txt
U projects/projectA/bin/script1.pl
U projects/projectA/bin/script2.pl
...

The "U" standards for update and indicates that the file was updated (i.e. created) on your machine. Alternatively, you could checkout each individual project as follows:

cvs co projects/projectA
cvs co projects/projectB
cvs co projects/projectC

Useful Commands

Adding new directories

Go to the directory you want to add the directory in and create the directory the way you would normally do it: cd newDirectoryName. Next you need to tell CVS that it has been added. To do this use the cvs add command as follows:

cvs add newDirectoryName.

Adding Text files

To add a text file to cvs, you must add the file and then commit the file.
  1. cvs add newfile
  2. cvs commit -m "message about file" newfile

Adding Binary files

To add a binary file to cvs, you must add the file with the -kb option and then commit the file.

  1. cvs add -kb newbinaryfile
  2. cvs commit -m "message about file" newbinaryfile

Modifying files

To modify a file and save it in your CVS repository, just edit as you would normally. When you want to commit your changes to the repository, use the cvs commit command again.

cvs commit -m "explanation of what changed" filename

That's it! You now have a record of what was changed and reverse back to older versions of the file if you need to.

What version of the file do you have?

To know what version of file you have, use the cvs status command:

cvs status filename

You'll see a bunch of information about the file in CVS with this command, but the "Working revision" will tell which version of the file you have.

You can use the cvs log command to see what other versions of a file are availabile and see the message that was given when the file was commited into cvs.

cvs log filename

Determining differences between versions

To determine the differences between to two versions of the same file you can use the cvs diff command:

cvs diff -r 1.5 -r 1.4 filename

This command compares version 1.5 and version 1.4 of the file and shows you the differences.

How to get a particular version of a file

To get an old version of a file, use the cvs update command:

cvs update -r 1.4 filename

This command gives you version 1.4 of the specified file.