Next: , Previous: Removing Directories, Up: Other Useful CVS Commands

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:

     floss$ cp oldname newname
     floss$ rm oldname

Here's the equivalent in CVS:

     floss$ mv oldname newname
     floss$ cvs remove oldname
       (output omitted)
     floss$ cvs add newname
       (output omitted)
     floss$ 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:

     floss$ mkdir newdir
     floss$ cvs add newdir
     floss$ mv olddir/* newdir
     mv: newdir/CVS: cannot overwrite directory
     floss$ cd olddir
     floss$ cvs rm foo.c bar.txt
     floss$ cd ../newdir
     floss$ cvs add foo.c bar.txt
     floss$ cd ..
     floss$ cvs commit -m "moved foo.c and bar.txt from olddir to newdir"
     floss$ 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. Later, you'll learn about a more drastic method of moving directories that involves making the change directly in the repository. However, that method is best saved for emergencies; whenever possible, it's best to handle everything with CVS operations inside working copies.

Karl Fogel wrote this book. Buy a printed copy via his homepage at

copyright  ©  September 17 2019 sean dreilinger url: