Introduction
The principle of CVS is to have a central location ("repository"), where the files of a project are stored. In order to work on a file, one has to "check out" the project (which is called "module" in CVS), which creates a "working directory", which is an exact copy of the repository. After editing, the file(s) is "checked in" again (which is called "commit" in CVS), which updates the central repository. It is possible to test whether the working directory is still synchronous with the repository and update the local files if necessary ("update"). If two people are working in separate working directories on the same file and both commit, conflict could arise - CVS notifies the user about that and marks the respective lines in the file.
Basic Commands
For each command, CVS has to know where the respective repository is located. Let's assume you work on a host alpha, which is also where the repository is located, e.g., /home/staff/roman/CVS (called "root" in CVS). Then, this would be the command to checkout a module named "foobar":
cvs -d/home/staff/roman/CVS checkout foobar
(cvs [-d root] <cvs-command> [module])
This causes the creation of a directory foobar in the folder where the command was executed, with the entire project files included. Usually, "checkout" is only necessary in the beginning, subsequently only "update" and "commit" are used.
To avoid typing the entire root-path for each CVS-command, you can use a special environment variable:
export CVSROOT=/home/staff/roman/CVS
This could be added to
~/.bashrc, for instance. From now on, I will assume that this variable is set and drop the -d switch.
The CVS-root can also be on a different machine than the working directory, provided that the user has ssh-access there. In this case, the CVS-root path is specified as such:
:ext:johndoe@alpha.example.org:/home/staff/roman/CVS
(:ext:$USER@$HOST:$ROOTPATH)
Then, you also need to tell CVS that it should use ssh to connect to the server:
export CVS_RSH=ssh
(again, this can be added to
~/.bashrc for convenience)
To add a new file, which was created in the working directory, to an existing module, this command is used:
cvs add file.cpp
This needs to be executed inside the working directory (or in its subdirectories). CVS will add the file to the repository the next time a "commit" is executed (see below). With the same command, also subdirectories in the project-tree can be added.
If several people are working on the same module, you can update your working directory with the command
cvs update
This needs to be executed within the working directory and synchronizes it with the current state of the repository.
Finally, To write your changes to the repository, the following command is used:
cvs commit
Again, to be executed in the working directory. Invoking this command brings up an editor where you can/should shortly describe your changes. This information will then be sent to all persons who are involved in this project (this list is maintained in the CVS-root). Receiving such a CVS notification means also that you should update your working directory.
For further information, see the
CVS manual wiki, the very nice
introduction by Gerald Pfeifer or the man page of cvs.
Some useful commands:
Force tag a file that has already been tagged:
cvs tag -F Release_1_2 File.cpp
Replace CVS-root server in a working directory structure:
for i in `grep -r oldhost *| cut -d: -f1`; do cat $i | sed 's/oldhost/newhost/' > $i.tmp; mv $i.tmp $i ; done
Show differences after having just committed (comparing with version from 1 hour ago):
cvs diff -D "1 hour ago"
Rollback to previous version of one specific file:
cvs checkout -p -r 1.x file.java > file.java
cvs commit (-m "Rollback file.java") file.java
(-p: prevent sticky tag, but write to stdout)
(-r: version. also possible: -D "date")
(commit -m: log message, otherwise vi is called as usual)
when it's one specific file. This prevents file.java being given a sticky tag
of the version you've checked out, making it possible to commit the old
version to replace the undesired version, as above.
Roman Schindlauer Last modified Thu Oct 5, 2006