Here is short and quick command examples for mostly used CVS commands. If you'd rather see a full list of commands of CVS, see CVS command reference
Check CVS terms quick review if you have any term confusion when reading.
1. Create a Repository
Suppose you have cvs package installed on your computer/server, then it's time to chose where you put your repository on a file system, I chose /var/cvs
cvs -d /var/cvs init
Time to setup your environment, you may want to add the following lines to your .cshrc, .bash_profile, etc..
#CVS Environment variables
setenv CVSROOT /var/cvs
setenv CVSEDITOR emacs #CVS Environment variables
That just tells the system where your default repository is, and for now you only need one repository. Now make sure that environment variable is set, by executing the line that you added, or equivalently:
(or .cshrc if applicable).
2. Add a Project
Suppose you have a project under your home directory, you want add it into CVS to have revision control. the directory is called ProjectABC
cvs import -m "Project ABC CVS start " ProjectABC yourname start
"yourname" and "start" are really unimportant - they are just version and "vendor" labels.
3. Check out a Project
Checking out a project in CVS will create a CVS working copy.
rm -rf ProjectABC
cvs checkout ProjectABC
Now you have a directory called ProjectABC, which should have a subdirectory called CVS. (all directories under CVS control will have this subdirectory).
4. Adding Subdirectories or files
Adding subdirectories or files to CVS is desireable. I tend to add the empty directory to CVS, then put the files into it, which works fine.
cvs add ProjectABC_1
The file/directory will be in the CVS repo in next commit.
cvs commit -m "original directories and files" *
If you omit the -m "original file" then cvs will start up your default editor for you to type a log message.
5. Updating the Working Directory
Update is one of the most important CVS commands. It updates your working directory from the repository, also tells you status of files.
Probably all you got was a message like "cvs update: Updating ."
Now vi ~/ProjectABC/filea.txt , and make some changes
$ cvs update
cvs update: Updating .
the 'M' indicates that you have modified the file. Other letters you sometimes get are P, which means CVS has patched the file from other updates in the repository, or U, which means CVS has copied a new file that wasn't yet in the working directory.
6. Check files differences between the Working Directory and Repository
Continue the test example from section #4, let's look at what we've changed with cvs diff:
cvs diff filea.txt
CVS prints a nice summary of what you've changed compared with the repository version. Now check in the change to the repository:
cvs commit filea.txt
When you do this, CVS pops up an editor. Just type a line like "first changes to file" on the first line and save/exit the editor.
Notice that the revision number is now 1.2.
7. Multiple Working Copies
You can have multiple working copies if you have more people working on the project, each user can have their own working directory
cvs checkout ProjectABC
Every user can freely commit their own changes to the repository if they work on different files. However, it's possible two or more people may change a same file, what CVS do to protect the conflict?
The very first person who commited the changes will have no problem, but the second and the third will get change conflict warning.
In that case, you might see the change that someone else has already made before you make a conflicting change. Of course sometimes conflicts will be unavoidable, CVS will leave this part to people to solve.
The best way to avoid this is to make a update to your working directory before you start make changes.
8. Log and Log Messages
Now go back to ~/ProjectABC and have a look at the log messages for the file filea.txt:
cvs log filea.txt
CVS prints a list of the log messages that you have added. A really nice feature is to have CVS just put the log messages in a comment block in the file each time changes are committed. Nicer yet is the fact the CVS does this intelligently enough that that comment blocks for latex.
Often, at certain points in time it is nice to mark all source files of a project.
cvs tag ProjectABC-Release-1.0
The tag text can be anything that you like, so you can make good use of it. You could later checkout the tagged version of the project with cd ~
cvs checkout -r ProjectABC-Release-1.0 ProjectABC
10. Remove a project from repository
I have one dedicated article for this, see How to delete a project from CVS