UCSD Main WebsiteUCSD Jacobs SchoolDepartment of Computer Science and Engineering
About CSECSE PeopleFacultyGraduate EducationUndergraduate EducationDepartment AdministrationContact CSE
spacer gif
spacer gif
CSE People
spacer gifspacer gif
spacer gif
plus signspacer gifAcademic Affairs
spacer gif
spacer gifspacer gifFaculty/Staff Intranet
spacer gif
plus signspacer gifFinancial Affairs
spacer gif
plus signspacer gifHuman Resources
spacer gif
minus signspacer gifComputing Support
spacer gifspacer gifServices
spacer gifspacer gifResources for TAs & Instructors
spacer gifspacer gifFacilities
spacer gifspacer gifRequest Help
spacer gifspacer gifOther Resources
spacer gifspacer gifWindows Resources
spacer gifspacer gifComputing Policy
spacer gif
plus signspacer gifFacilities
spacer gif
spacer gifspacer gifComputing FAQ
spacer gif
spacer gif
spacer gif
Search
spacer gifspacer gifspacer gif
 
 
Google
spacer gifspacer gif
spacer gif
spacer gif
spacer gif
spacer gif
spacer gifspacer gif
Home»Department Administration»Computing Support»Other resources»Software»CVS»Michelle Strout's CVS Notes
spacer gif
CVS Notes
spacer gif
spacer gifspacer gifspacer gif
spacer gif

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.

How to set up a cvs repository

  1. 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
    
  2. Initialize the repository
        % cvs init 
    
    (NOTE: notice that the directory /net/azulejo/disk1/mstrout/CodeExamples/CVSExample/Repository now exists)

How to put a Module in the repository

  1. First move into a currently active directory which you wish to make a Module for
        % cd MyProjDir
    
  2. 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.
    
  3. 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
    

How to edit and use a project in a CVS repository

  1. 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)
  2. Make a change to one of the files in the directory.
        % vi log.txt
    
  3. 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

Some notes on 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
    

Using tags

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.

  1. Tag the latest version of the code in your working directory. (NOTE: always good to do a commit first)
        % cvs tag FirstTurnIn
    
  2. 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
    

Adding a sub-directory to the CVS Module

  1. Create the new sub-directory within your working version of the module
        % cd MyProjDir
        % mkdir SubDir1
    
  2. 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 ..
    
  3. Do the necessary cvs adds
        > cvs add SubDir1
        > cvs add SubDir1/*    (Adds files in SubDir1)
        > cvs commit
    

Deleting a sub-directory from a CVS Module

  1. 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
    

Retrieving a previous version

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!

Using branching

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.

  1. Commit current code.
        % cvs commit
    
  2. Tag the current code
        % cvs tag before_new_image_code
    
  3. Create a new branch
        % cvs tag -b new_image_code
    
  4. 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.

  • Move back to trunk/main version of code.
        % cvs update -A
    
  • Move back to specified branch
        % cvs update -r new_image_code
    

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.

  1. Move to main branch
        % cvs update -A
    
  2. See what the differences are between the branch we want to merge with and the main branch.
        % cvs diff -r new_image_code
    
  3. 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.

spacer gif
spacer gif
spacer gifback to top ^
spacer gif
spacer gif
spacer gif
spacer gif
9500 Gilman Drive, La Jolla, CA 92093-0404
spacer gif
About CSE | CSE People | Faculty & Research | Graduate Education | Undergraduate Education
Department Administration | Contact CSE | Help | Search | Site map | Home
webmaster@cs.ucsd.edu
Official web page of the University of California, San Diego
Copyright © 2003 Regents of the University of California. All rights reserved.
spacer gif