Adding and Deleting Files
CVS treats file creation and deletion like other changes, recording such events in the files' histories. One way to look at this is to say that CVS records the history of directories as well as the files they contain.
CVS doesn't assume that newly created files should be placed under its control; this would do the wrong thing in many circumstances. For example, one needn't record changes to object files and executables, since their contents can always be re-created from the source files (one hopes). Instead, if you create a new file, cvs update will flag it with a ? character until you tell CVS what you intend to do with it.
To add a file to a project, you must first create the file, and then use the cvs add command to mark it for addition. Then, the next call to cvs commit will add the file to the repository. For example, here's how you might add a README file to the httpc project:
$ ls CVS Makefile httpc.c poll-server $ vi README ... enter a description of httpc ... $ ls CVS Makefile README httpc.c poll-server $ cvs update cvs update: Updating . ? README --- CVS doesn't know about this file yet. $ cvs add README cvs add: scheduling file `README' for addition cvs add: use 'cvs commit' to add this file permanently $ cvs update --- Now what does CVS think? cvs update: Updating . A README --- The file is marked for addition. $ cvs commit README ... CVS prompts you for a log entry ... RCS file: /u/jimb/cvs-class/rep/httpc/README,v done Checking in README; /u/src/master/httpc/README,v <-- README initial revision: 1.1 done $
CVS treats deleted files similarly. If you delete a file and then run cvs update, CVS doesn't assume you intend the file for deletion. Instead, it does something benign -- it re-creates the file with its last recorded contents, and flags it with a U character, as for any other update. (This means that if you want to undo the changes you've made to a file in your working directory, you can simply delete the files, and then let cvs update recreate them.)
To remove a file from a project, you must first delete the file, and then use the cvs rm command to mark it for deletion. Then, the next call to cvs commit will delete the file from the repository.
Committing a file marked with cvs rm does not destroy the file's history. It simply adds a new revision, which is marked as "non-existent." The repository still has records of the file's prior contents, and can recall them as needed — for example, by cvs diff or cvs log.
There are several strategies for renaming files; the simplest is to simply rename the file in your working directory, and run cvs rm on the old name, and cvs add on the new name. The disadvantage of this approach is that the log entries for the old file's content do not carry over to the new file. Other strategies avoid this quirk, but have other, stranger problems.
You can add directories just as you would ordinary files.