Modelling clouds and climate

Add and Delete Code

Path: Contents > Other CVS Commands > Add and Delete Code
Site Map

Contents

About CVS
  • Setting up CVS
  • Using the CVS Server
  • Commands and
      Terminology
  • pcl-cvs
    Using CVS
  • How was SCM set up?
      (import)
  • Getting the ubcscm
      (checkout)
  • Making changes
      (update/diff)
  • Commiting your changes
      (commit)
  • Releasing you work
      (release)
    Other CVS Commands
  • Examining Changes
      (log)
  • Add and Delete Code
      (add/del)
  • Status/revisions
  • Tags
  • Branches
    Spetial Topics
  • Writing Log
  • Handling Conflicts
    References



    Web Contact: Phil Austin
    Site created with Cheetah.

    Last updated: Mar 13 2003
  • Adding and Deleting Code

    cvs add (synonyms: ad new)

    cvs remove (synonyms: rm delete)

    Adding Files

    Adding a file is a two-step process: First you run the add command on it, then commit. The file won't actually appear in the repository until commit is run:

     $ pwd
     /home/somewhere/ubcscm
     $ ls newfile.f
     ls: : No such file or directory
     $ emacs newfile.f
     $ ls newfile.f
     newfile.f
     $ cvs add newfile.f
     cvs add: scheduling file `newfile.f' for addition
     cvs add: use 'cvs commit' to add this file permanently
     $ cvs commit -m "adding newfile.f" newfile.f
     RCS file: /nfs/roc/home/cvs/ubcscm/newfile.f,v
     done
     Checking in newfile.f;
     /nfs/roc/home/cvs/ubcscm/newfile.f,v  <--  newfile.f
     initial revision: 1.1
     done
     $
     

    Adding Directories

    Unlike adding a file, adding a new directory is done in one step; there's no need to do a commit afterwards:

     $ mkdir newdir
     $ cvs add newdir
     Directory /nfs/roc/home/cvs/ubcscm/newdir added to the repository
     $
     

    If you look inside the new directory in the working copy, you'll see that a CVS subdirectory was created automatically by add:

     $ ls newdir
     CVS/
     $ ls newdir/CVS
     Entries     Repository  Root
     $
     

    Now you can add files (or new directories) inside it, as with any other working copy directory.

    Removing Files

    Removing a file is similar to adding one, except there's an extra step. You have to remove the file from the working copy first and then use remove command:

     $ rm newfile.f
     $ cvs remove newfile.f
     cvs remove: scheduling 'newfile.f' for removal
     cvs remove: use 'cvs commit' to remove this file permanently
     $ cvs ci -m "removed newfile.f" newfile.f
     Removing newfile.f;
     /nfs/roc/home/cvs/ubcscm/newfile.f,v  <--  newfile.f
     new revision: delete; previous revision: 1.1
     done
     $
     

    Notice how, in the second and third commands, we name newfile.f explicitly even though it doesn't exist in the working copy anymore. Of course, in the commit, you don't absolutely need to name the file, as long as you don't mind the commit encompassing any other modifications that may have taken place in the working copy.

    Removing Directories

    As I said before, CVS doesn't really keep directories under version control. Instead, as a kind of cheap substitute, it offers certain odd behaviors that in most cases do the "right thing". One of these odd behaviors is that empty directories can be treated specially. If you want to remove a directory from a project, you first remove all the files in it and then run update in the directory above it with the -P flag:

     $ cd ..
     $ cvs update -P
     cvs update: Updating .
     cvs update: Updating newdir
     

    The -P option tells update to "prune" any empty directories - that is, to remove them from the working copy. Once that's done, the directory can be said to have been removed; all of its files are gone, and the directory itself is gone (from the working copy, at least, although there is actually still an empty directory in the repository).

    An interesting counterpart to this behavior is that when you run a plain update, CVS does not automatically bring new directories from the repository into your working copy. There are a couple of different justifications for this, none really worth going into here. The short answer is that from time to time you should run update with the -d flag, telling it to bring down any new directories from the repository.

    Renaming Files And Directories

    Renaming a file is equivalent to creating it under the new name and removing it under the old. In Unix, the commands are:

     $ cp oldname newname
     $ rm oldname
     
    Here's the equivalent in CVS:
     $ mv oldname newname
     $ cvs remove oldname
       (output omitted)
     $ cvs add newname
       (output omitted)
     $ cvs ci -m "renamed oldname to newname" oldname newname
       (output omitted)
     $
     

    For files, that's all there is to it. Renaming directories is not done very differently: create the new directory, cvs add it, move all the files from the old directory to the new one, cvs remove them from the old directory, cvs add them in the new one, cvs commit so everything takes effect, and then do cvs update -P to make the now-empty directory disappear from the working copy. That is to say:

     $ mkdir newdir
     $ cvs add newdir
     $ mv olddir/* newdir
     mv: newdir/CVS: cannot overwrite directory
     $ cd olddir
     $ cvs rm foo.c bar.txt
     $ cd ../newdir
     $ cvs add foo.c bar.txt
     $ cd ..
     $ cvs commit -m "moved foo.c and bar.txt from olddir to newdir"
     $ cvs update -P
     

    Note: the warning message after the third command. It's telling you that it can't copy olddir's CVS/ subdirectory into newdir because newdir already has a directory of that name. This is fine, because you want olddir to keep its CVS/ subdirectory anyway.

    Obviously, moving directories around can get a bit cumbersome. The best policy is to try to come up with a good layout when you initially import your project so you won't have to move directories around very often.