< Zurück | Inhalt | Weiter >

8.2.2 Import

Are you wanting to use CVS on an existing project? Have you already got your project at least partly underway? Let’s look at how to enter all those files into CVS with a single command.

Not every file that is in a working directory needs to be kept under source control. Some, like .class files, are created from the .java source files. Others may be just scratch files that you don’t want to keep versioned.

To automatically exclude certain files from ever being included in your repository, CVS uses a file called .cvsignore that lists filename patterns. Any filename matching a pattern will be ignored by all CVS commands.

Here is a .cvsignore file that we recommend for Java developers:



This will exclude any file whose name ends in .class or .zip. Note that the comparison is strictly based on a name, not the actual contents. CVS doesn’t know what a “class” file is; it is only excluding a file based on its name.

Certain files are not really source files and can’t be managed as such, but we would still like to keep versions and a history of changes for them. A good example would be an image file. For example, you may have a corporate logo in a file called logo.jpg and at some point you may get a new or revised ver- sion of that file. You can use CVS to track such files, but you need to tell CVS that this is a binary file, so that CVS doesn’t try to do some special substitutions that it does on check-in and check-out. (More about those substitutions later.)

For now, let’s just consider how to tell CVS which files are binary. We can do that on the command line when we create a new file, but for importing a lot of files at once, and to avoid the need to remember doing that each time we add a file, we can put patterns for binary filenames in a CVS file called


Here is a .cvswrappers file that we recommend for Java developers:


# A recommended .cvswrappers file


# jar files - treat as binary:

*.jar -k 'b'


# Image file formats - treat as binary:

*.gif -k 'b'

*.jpg -k 'b'

*.png -k 'b'

*.tif -k 'b'


# Document file formats - treat as binary

# both MSOffice and OpenOffice.org file formats:

*.doc -k 'b'

*.ppt -k 'b'

*.xls -k 'b'

*.sx? -k 'b'

The format of the file is very UNIX-like. A leading # means that the rest of the line is a comment. The asterisk matches any number of any characters. The question mark matches a single character.

Now we’re ready to import. The .cvsignore file should be placed in the topmost directory of the set of files that you want to import. Then, from that directory, issue the command:

$ cvs import Project YourCo import

where Project is whatever name you want to use for this project (or module) in CVS, and YourCo is the name of your company or some other designator to differentiate this source from other third-party packages that you may keep in your repository.

Most importantly, execute the cvs import command from within the directory, even though the name of the project is likely (but doesn’t have to be) the same as the name of the directory in which you sit.

For example, consider a fragment of the filesystem shown in Figure 8.1. You would want to cd into the directory coolj and then issue the import command:

$ cd coolj

$ cvs import coolj GJSinc import










Figure 8.1 A sample directory structure prior to import

This will create a module named coolj in the repository, whose contents are all the directories and subdirectories that you see there. But you had to be in the coolj directory, which may seem counter-intuitive.

Now go to some other directory, one that is not part of the coolj part of the tree, and check out a copy of the source. For example:

$ cd

$ mkdir devsrc

$ cd devsrc


$ cvs checkout coolj


It is important to check out the source after you’ve done the import, and before you make any changes, because the part of the filesystem that you imported remains untouched. It has no CVS knowledge, so you can’t commit changes from that directory, unless you somehow make it CVS-aware. Since these files are your originals, until you’ve verified that the cvs import has gone as planned, it’s best not to disturb those files. Create a new directory and check out the module there.

What do you see after the checkout? There should be a single directory, coolj, in the directory where you did the checkout (since it was empty when you started). That directory contains a copy of all the files that you checked in, along with a directory named CVS inside that directory and every subdirectory. The CVS directories contain administrative files that help CVS keep track of things for you, which means no CVS tracking information needs to be kept in

your source. You should never need to mess with the files in the CVS directory; see the Cederqvist reference in Section 8.6 for more information about these files.