Previous Section  < Day Day Up >  Next Section

Recipe 18.6. Using CVS for a Single-User Local Repository

18.6.1 Problem

You would rather use CVS for your local, personal repository because you plan to also use it for larger projects, and you want to stick to learning a single system. Or your personal repository is getting complex, so you need the additional abilities of CVS to manage it, such as more complex directory structures, and being able to checkout multiple files or entire directories at once.

18.6.2 Solution

CVS scales nicely from small personal projects to large projects without a problem. Installation is simple. Both RPMs and .debs are named "cvs"; if you prefer to install from sources, get them from

After installing CVS, create your personal repository with these commands:

$ mkdir ~/cvsroot

$ chmod -R 700 ~/cvsroot

$ cvs -d ~/cvsroot init

Now select a directory of files to store in your repository. Change to that directory, and import the directory into your CVS repository:

$ cd /scripts

$ cvs -d ~/cvsroot import scripts jenns_configs version_1

N scripts/useradd.txt

N scripts/postfix_ube.txt

N scripts/

No conflicts created by this import

During the import, your default editor will open, displaying this text:

CVS: -----------------------------------------------------

CVS: Enter Log.  Lines beginning with `CVS:' are removed automatically


CVS: -----------------------------------------------------

Enter your project description here (e.g., "Jenn's system administration scripts for Slackware 9"). Make this detailed enough so that six months from now, it will still make sense.

To check out a file for editing, you must first create a working directory. This directory must be outside of the directory that holds your CVS repository. Then change to the working directory, and check out a file:

$ mkdir ~/sandbox

$ cd ~/sandbox

$ cvs -d ~/cvsroot  checkout  scripts/postfix_ube.txt

cvs checkout: Updating scripts

U scripts/postfix_ube.txt

Checking out files from the CVS repository creates a CVS sandbox in your working directory. The sandbox is the local working directory where all of your actual work takes place. When you check out files from CVS, a batch of CVS admininistrative files are installed in the sandbox. Always work from a sandbox; never enter a CVS repository to edit files. Your sandbox can have any name you choose.

The file you just checked out is in the scripts directory, so that is your sandbox, and you should change to that directory to edit the file:

$ cd scripts

$ vim postfix_ube.txt

When you're finished editing the file, save it in the normal fashion, and put it back in the CVS repository using the commit subcommand:

$ cvs commit

cvs commit: Examining .

/home/jenn/cvsroot/scripts/postfix_ube.txt,v  <--  postfix_ube.txt

new revision: 1.2; previous revision: 1.1

Again, your default editor will open, and you'll be asked to write a log entry detailing your changes.

As long as you are in the sandbox, which in this example is ~/sandbox/scripts, you can omit specifying the name of the repository for checkouts and commits.

18.6.3 Discussion

This is the CVS command syntax:

cvs [ global_options ] command [ command_options ] [ command_args ]

CVS is all about record keeping. Take the time to make useful log entries—you will thank yourself many times during the life of your CVS project.

You can name your CVS root directory anything you like.

jenns_configs and version_1 are the vendor tag and release number, respectively. While you may not care about these, CVS requires them. The vendor tag usually identifies whoever supplies the source files, and the version number is the starting version number for the project.

You can collect all the files you want for a new project in a temporary directory, then delete it after they are safely imported into the repository. Test the import by checking out a sandbox and verifying that the files in the sandbox are correct before you delete the originals. Once you have created your sandbox and imported the files into the repository, you don't need to keep the originals; they're just taking up space.

A single directory, and all of its files and subdirectories, is a project. Every project must be stored in a directory, even if it is just a single file.

You can check out single files, space-delimited lists of files, or entire directories:

$ cvs checkout scripts/postfix_ube.txt

$ cvs checkout scripts/postfix_ube.txt scripts/

$ cvs checkout scripts

Unlike RCS, checking out files in CVS does not lock them to prevent other users from checking them out at the same time. Thus, you can grab an entire directory without hindering other users.

18.6.4 See Also

    Previous Section  < Day Day Up >  Next Section