Note: Michelle is no longer maintaining this page.
What follows are some practical notes for how to use CVS.
To read
more about CVS and learn more tricks see some of these web sites.
- Set CVSROOT to path where the repository will be located.
(NOTE: make sure that the Repository directory doesn't already exist)
% setenv CVSROOT /net/azulejo/disk1/mstrout/CodeExamples/CVSExample/Repository
- Initialize the repository
% cvs init
(NOTE: notice that the directory
/net/azulejo/disk1/mstrout/CodeExamples/CVSExample/Repository now
exists)
- First move into a currently active directory which you wish to
make a Module for
% cd MyProjDir
- Now import the directory into CVS and create a module.
(NOTE: this is done within the directory you want to be archived)
% cvs import -m "First import" MyProjDir tag1 tag2
N MyProjDir/log.txt
N MyProjDir/main.cpp
No conflicts created by this import
-m "First Import": specifies log message
MyProjDir: specifies name of Module
tag1 and tag2: logical tags which I never use
(NOTE: If -m isn't used on the command line then vi will start so that
you can edit a log message. To start typing press 'a' or 'i'. To
finish and save the message go to escape mode by pressing ESC and then
type ':wq'. You can use a different editor by using the -e option for
cvs)
-e editor
Use editor to enter revision log information.
Overrides the setting of the CVSEDITOR and the EDITOR
environment variables.
- Backup original directory: You will no longer be working in the
original directory MyProjDir. Instead you will be checking out a
working version of that directory from the repository (which could
have the same name). I suggest moving the original directory so that
you have a last ditch backup.
% mv MyProjDir MyProjDir.bak
- Checkout the directory from the CVS repository to make your own
working directory.
% cvs checkout MyProjDir
# checking out a project, if CVSROOT isn't specified, have to put -d
# before checkout keyword
% cvs -d/net/azulejo/disk1/mstrout/CodeExamples/CVSExample/Repository checkout MyProjDir
(NOTE: should create a directory called MyProjDir which contains all
the files and sub-directories the original MyProjDir contained plus a
CVS sub directory)
- Make a change to one of the files in the directory.
% vi log.txt
- Commit the change back to the repository
% cvs commit
CVS bring up VI like so...
CVS:
----------------------------------------------------------------------
CVS: Enter Log. Lines beginning with `CVS:' are removed automatically
CVS:
CVS: Committing in .
CVS:
CVS: Modified Files:
CVS: log.txt
CVS:
----------------------------------------------------------------------
(NOTE: one of the nice things about CVS is that it figures out what
files have been changed and lists those files in the log comments.
You only have to make one log entry for all changes)
Here are some other commands which are useful:
#### add a new file to the module
% cvs add newfile.txt
% cvs commit -m "commit message for new file"
#### gives info about all files
% cvs log
% cvs log newfile.txt
#### if 2+ people have working directories and want to sync
#### your working version with the repository
% cvs update
Situation: someone else has committed a change to a file which you
have edited in your working directory.`
What Happens:
- cvs commit won't work, you get a message like this
cvs commit: Up-to-date check failed for `log.txt'
- cvs update will attempt to do a merge of the changes
tandem% cvs update log.txt
RCS file:
/net/tandem/disk1/mstrout/CVSRepository/SparseTiling/log.txt,v
retrieving revision 1.10
retrieving revision 1.11
Merging differences between 1.10 and 1.11 into log.txt
rcsmerge: warning: conflicts during merge
cvs update: conflicts found in log.txt
C log.txt
Great site which talks about tagging and branching:
CVS
Let's say you turn in your project at one point, and then have to
update the project for another assignment. (This scenario will occur
in compilers class). At some point you realize you have really messed
up and you want to go back to the version of the project you turned
in. Or you may want to see the differences between that version and
the current code. (use cvs diff)
You can create symbolic tags which make this very easy.
- Tag the latest version of the code in your working directory.
(NOTE: always good to do a commit first)
% cvs tag FirstTurnIn
- If needed later on use the -r option on export.
(NOTE: make sure you are in a directory where a whole new MyProjDir
can be created. You don't want to accidentally overwrite your current
working version of MyProjDir)
% cvs checkout -r FirstTurnin MyProjDir
- Create the new sub-directory within your working version of the
module
% cd MyProjDir
% mkdir SubDir1
- Move to that directory and create some files
(NOTE: this isn't necessary but it shows how you would add the files
within the subdirectory as well)
% cd SubDir1
% vi README
% cd ..
- Do the necessary cvs adds
> cvs add SubDir1
> cvs add SubDir1/* (Adds files in SubDir1)
> cvs commit
- Go to directory above subdirectory you want to delete and then do
a cvs release.
% cvs release -d SubDir1/
You have [0] altered files in this repository.
Are you sure you want to release (and delete) directory `SubDir1/': y
How to checkout previous versions of a
file and REPLACE the current working version. The -p flag makes the file go
to standard out so it prevents stickiness. Stickiness is a pain.
% cvs update -r 1.3 -p myBvec_smooth.c > temp.c
% mv temp.c myBvec_smooth.c
Possibly an easier way is this:
With two `-j revision' flags, the update (and checkout) command can
merge the differences between any two revisions into your
working file.
% cvs update -j 1.5 -j 1.3 backend.c
will undo all changes made between revision 1.3 and 1.5. Note the
order of the revisions!
Great site which talks about tagging and branching.
CVS
Let's say you want to try something out but still be able to easily
come back to the current version of the code if your experiment
doesn't work. However, you want to keep the experiment around, or you
want to be able to edit the main branch at the same time.
- Commit current code.
% cvs commit
- Tag the current code
% cvs tag before_new_image_code
- Create a new branch
% cvs tag -b new_image_code
- Move to new branch
% cvs update -r new_image_code
Now any changes which are made will be commited to the new branch. To
switch back and forth between the branch and the trunk use the
following commands.
Make sure to do a commit before switching to another branch. Update
will overwrite your current working files with the latest version from
the branch you specify, so all changes will be lost unless they have
been committed.
Let's say your experiment worked and you want to merge the branches.
- Move to main branch
% cvs update -A
- See what the differences are between the branch we want to merge
with and the main branch.
% cvs diff -r new_image_code
- Merge the branch into the main branch.
% cvs update -j new_image_code
You will be told about any conflicts during the merge, and you won't
be allowed to commit the files until those conflicts are dealt with.
 |