1<div id="Adding-and-removing"></div> 2<div class="header"> 3<p> 4Next: [[cvs: History browsing#History browsing|History browsing]], Previous: [[cvs: Recursive behavior#Recursive behavior|Recursive behavior]], Up: [[cvs#Top|Top]] |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p> 5</div> 6<div id="Adding_002c-removing_002c-and-renaming-files-and-directories"></div> 7== Adding, removing, and renaming files and directories == 8 9In the course of a project, one will often add new 10files. Likewise with removing or renaming, or with 11directories. The general concept to keep in mind in 12all these cases is that instead of making an 13irreversible change you want <small>CVS</small> to record the 14fact that a change has taken place, just as with 15modifying an existing file. The exact mechanisms to do 16this in <small>CVS</small> vary depending on the situation. 17 18<div class="menu-preformatted" style="font-family: serif"> 19 [[#Adding files to a directory|• Adding files]]:: Adding files 20 [[#Removing files|• Removing files]]:: Removing files 21 [[#Removing directories|• Removing directories]]:: Removing directories 22 [[#Moving and renaming files|• Moving files]]:: Moving and renaming files 23 [[#Moving and renaming directories|• Moving directories]]:: Moving and renaming directories 24</div> 25 26 27---- 28 29<div id="Adding-files"></div> 30<div class="header"> 31<p> 32Next: [[#Removing files|Removing files]], Up: [[#Adding, removing, and renaming files and directories|Adding and removing]] |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p> 33</div> 34<div id="Adding-files-to-a-directory"></div> 35=== Adding files to a directory === 36<div id="index-Adding-files"></div> 37 38To add a new file to a directory, follow these steps. 39 40 41* You must have a working copy of the directory. See [[cvs: Overview#Getting the source|Getting the source]]. 42 43 44* Create the new file inside your working copy of the directory. 45 46 47* Use ‘<code>cvs add <var>filename</var></code>’ to tell <small>CVS</small> that you want to version control the file. If the file contains binary data, specify ‘<code>-kb</code>’ (see [[cvs: Handling binary files#Handling binary files|Binary files]]). 48 49 50* Use ‘<code>cvs commit <var>filename</var></code>’ to actually check in the file into the repository. Other developers cannot see the file until you perform this step. 51 52You can also use the <code>add</code> command to add a new 53directory. 54 55Unlike most other commands, the <code>add</code> command is 56not recursive. You cannot even type ‘<code>cvs add 57foo/bar</code>’! Instead, you have to 58 59<div class="example" style="margin-left: 3.2em"> 60 $ cd foo 61 $ cvs add bar 62</div> 63 64<div id="index-add-_0028subcommand_0029"></div> 65;<div id="index-cvs-add"></div>Command<nowiki>:</nowiki> <strong>cvs add</strong><em> <nowiki>[</nowiki><code>-k</code> kflag<nowiki>]</nowiki> <nowiki>[</nowiki><code>-m</code> message<nowiki>]</nowiki> files …</em> 66 67: Schedule <var>files</var> to be added to the repository. The files or directories specified with <code>add</code> must already exist in the current directory. To add a whole new directory hierarchy to the source repository (for example, files received from a third-party vendor), use the <code>import</code> command instead. See [[cvs: Guide to CVS commands#import—Import sources into CVS, using vendor branches|import]]. 68 69: The added files are not placed in the source repository until you use <code>commit</code> to make the change permanent. Doing an <code>add</code> on a file that was removed with the <code>remove</code> command will undo the effect of the <code>remove</code>, unless a <code>commit</code> command intervened. See [[#Removing files|Removing files]], for an example. 70 71: The ‘<code>-k</code>’ option specifies the default way that this file will be checked out; for more information see [[cvs: Keyword substitution#Substitution modes|Substitution modes]]. 72 73: The ‘<code>-m</code>’ option specifies a description for the file. This description appears in the history log (if it is enabled, see [[cvs: Reference manual for Administrative files#The history file|history file]]). It will also be saved in the version history inside the repository when the file is committed. The <code>log</code> command displays this description. The description can be changed using ‘<code>admin -t</code>’. See [[cvs: Guide to CVS commands#admin—Administration|admin]]. If you omit the ‘<code>-m <var>description</var></code>’ flag, an empty string will be used. You will not be prompted for a description. 74 75For example, the following commands add the file 76‘<tt>backend.c</tt>’ to the repository: 77 78<div class="example" style="margin-left: 3.2em"> 79 $ cvs add backend.c 80 $ cvs commit -m "Early version. Not yet compilable." backend.c 81</div> 82 83When you add a file it is added only on the branch 84which you are working on (see [[cvs: Branching and merging#Branching and merging|Branching and merging]]). You can 85later merge the additions to another branch if you want 86(see [[cvs: Branching and merging#Merging can add or remove files|Merging adds and removals]]). 87 88 89---- 90 91<div id="Removing-files"></div> 92<div class="header"> 93<p> 94Next: [[#Removing directories|Removing directories]], Previous: [[#Adding files to a directory|Adding files]], Up: [[#Adding, removing, and renaming files and directories|Adding and removing]] |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p> 95</div> 96<div id="Removing-files-1"></div> 97=== Removing files === 98<div id="index-Removing-files"></div> 99<div id="index-Deleting-files"></div> 100 101Directories change. New files are added, and old files 102disappear. Still, you want to be able to retrieve an 103exact copy of old releases. 104 105Here is what you can do to remove a file, 106but remain able to retrieve old revisions: 107 108 109* Make sure that you have not made any uncommitted modifications to the file. See [[cvs: Overview#Viewing differences|Viewing differences]], for one way to do that. You can also use the <code>status</code> or <code>update</code> command. If you remove the file without committing your changes, you will of course not be able to retrieve the file as it was immediately before you deleted it. 110 111 112* Remove the file from your working copy of the directory. You can for instance use <code>rm</code>. 113 114 115* Use ‘<code>cvs remove <var>filename</var></code>’ to tell <small>CVS</small> that you really want to delete the file. 116 117 118* Use ‘<code>cvs commit <var>filename</var></code>’ to actually perform the removal of the file from the repository. 119 120When you commit the removal of the file, <small>CVS</small> 121records the fact that the file no longer exists. It is 122possible for a file to exist on only some branches and 123not on others, or to re-add another file with the same 124name later. <small>CVS</small> will correctly create or not create 125the file, based on the ‘<code>-r</code>’ and ‘<code>-D</code>’ options 126specified to <code>checkout</code> or <code>update</code>. 127 128<div id="index-Remove-_0028subcommand_0029"></div> 129;<div id="index-cvs-remove"></div>Command<nowiki>:</nowiki> <strong>cvs remove</strong><em> <nowiki>[</nowiki>options<nowiki>]</nowiki> files …</em> 130 131: Schedule file(s) to be removed from the repository (files which have not already been removed from the working directory are not processed). This command does not actually remove the file from the repository until you commit the removal. For a full list of options, see [[cvs: Quick reference to CVS commands#Quick reference to CVS commands|Invoking CVS]]. 132 133Here is an example of removing several files: 134 135<div class="example" style="margin-left: 3.2em"> 136 $ cd test 137 $ rm *.c 138 $ cvs remove 139 cvs remove: Removing . 140 cvs remove: scheduling a.c for removal 141 cvs remove: scheduling b.c for removal 142 cvs remove: use 'cvs commit' to remove these files permanently 143 $ cvs ci -m "Removed unneeded files" 144 cvs commit: Examining . 145 cvs commit: Committing . 146</div> 147 148As a convenience you can remove the file and <code>cvs 149remove</code> it in one step, by specifying the ‘<code>-f</code>’ 150option. For example, the above example could also be 151done like this: 152 153<div class="example" style="margin-left: 3.2em"> 154 $ cd test 155 $ cvs remove -f *.c 156 cvs remove: scheduling a.c for removal 157 cvs remove: scheduling b.c for removal 158 cvs remove: use 'cvs commit' to remove these files permanently 159 $ cvs ci -m "Removed unneeded files" 160 cvs commit: Examining . 161 cvs commit: Committing . 162</div> 163 164If you execute <code>remove</code> for a file, and then 165change your mind before you commit, you can undo the 166<code>remove</code> with an <code>add</code> command. 167 168 169<div class="example" style="margin-left: 3.2em"> 170 $ ls 171 CVS ja.h oj.c 172 $ rm oj.c 173 $ cvs remove oj.c 174 cvs remove: scheduling oj.c for removal 175 cvs remove: use 'cvs commit' to remove this file permanently 176 $ cvs add oj.c 177 U oj.c 178 cvs add: oj.c, version 1.1.1.1, resurrected 179</div> 180 181If you realize your mistake before you run the 182<code>remove</code> command you can use <code>update</code> to 183resurrect the file: 184 185<div class="example" style="margin-left: 3.2em"> 186 $ rm oj.c 187 $ cvs update oj.c 188 cvs update: warning: oj.c was lost 189 U oj.c 190</div> 191 192When you remove a file it is removed only on the branch 193which you are working on (see [[cvs: Branching and merging#Branching and merging|Branching and merging]]). You can 194later merge the removals to another branch if you want 195(see [[cvs: Branching and merging#Merging can add or remove files|Merging adds and removals]]). 196 197 198---- 199 200<div id="Removing-directories"></div> 201<div class="header"> 202<p> 203Next: [[#Moving and renaming files|Moving files]], Previous: [[#Removing files|Removing files]], Up: [[#Adding, removing, and renaming files and directories|Adding and removing]] |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p> 204</div> 205<div id="Removing-directories-1"></div> 206=== Removing directories === 207<div id="index-Removing-directories"></div> 208<div id="index-Directories_002c-removing"></div> 209 210In concept removing directories is somewhat similar to 211removing files—you want the directory to not exist in 212your current working directories, but you also want to 213be able to retrieve old releases in which the directory 214existed. 215 216The way that you remove a directory is to remove all 217the files in it. You don’t remove the directory 218itself; there is no way to do that. 219Instead you specify the ‘<code>-P</code>’ option to 220<code>cvs update</code> or <code>cvs checkout</code>, 221which will cause <small>CVS</small> to remove empty 222directories from working directories. 223(Note that <code>cvs export</code> always removes empty directories.) 224Probably the 225best way to do this is to always specify ‘<code>-P</code>’; if 226you want an empty directory then put a dummy file (for 227example ‘<tt>.keepme</tt>’) in it to prevent ‘<code>-P</code>’ from 228removing it. 229 230Note that ‘<code>-P</code>’ is implied by the ‘<code>-r</code>’ or ‘<code>-D</code>’ 231options of <code>checkout</code>. This way 232<small>CVS</small> will be able to correctly create the directory 233or not depending on whether the particular version you 234are checking out contains any files in that directory. 235 236 237---- 238 239<div id="Moving-files"></div> 240<div class="header"> 241<p> 242Next: [[#Moving and renaming directories|Moving directories]], Previous: [[#Removing directories|Removing directories]], Up: [[#Adding, removing, and renaming files and directories|Adding and removing]] |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p> 243</div> 244<div id="Moving-and-renaming-files"></div> 245=== Moving and renaming files === 246<div id="index-Moving-files"></div> 247<div id="index-Renaming-files"></div> 248<div id="index-Files_002c-moving"></div> 249 250Moving files to a different directory or renaming them 251is not difficult, but some of the ways in which this 252works may be non-obvious. (Moving or renaming a 253directory is even harder. See [[#Moving and renaming directories|Moving directories]].). 254 255The examples below assume that the file <var>old</var> is renamed to 256<var>new</var>. 257 258<div class="menu-preformatted" style="font-family: serif"> 259 [[#The Normal way to Rename|• Outside]]:: The normal way to Rename 260 [[#Moving the history file|• Inside]]:: A tricky, alternative way 261 [[#Copying the history file|• Rename by copying]]:: Another tricky, alternative way 262</div> 263 264 265---- 266 267<div id="Outside"></div> 268<div class="header"> 269<p> 270Next: [[#Moving the history file|Inside]], Up: [[#Moving and renaming files|Moving files]] |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p> 271</div> 272<div id="The-Normal-way-to-Rename"></div> 273==== The Normal way to Rename ==== 274 275 276The normal way to move a file is to copy <var>old</var> to 277<var>new</var>, and then issue the normal <small>CVS</small> commands 278to remove <var>old</var> from the repository, and add 279<var>new</var> to it. 280 281<div class="example" style="margin-left: 3.2em"> 282 $ mv <var>old</var> <var>new</var> 283 $ cvs remove <var>old</var> 284 $ cvs add <var>new</var> 285 $ cvs commit -m "Renamed <var>old</var> to <var>new</var>" <var>old</var> <var>new</var> 286</div> 287 288This is the simplest way to move a file, it is not 289error-prone, and it preserves the history of what was 290done. Note that to access the history of the file you 291must specify the old or the new name, depending on what 292portion of the history you are accessing. For example, 293<code>cvs log <var>old</var></code> will give the log up until the 294time of the rename. 295 296When <var>new</var> is committed its revision numbers will 297start again, usually at 1.1, so if that bothers you, 298use the ‘<code>-r rev</code>’ option to commit. For more 299information see [[cvs: Revisions#Assigning revisions|Assigning revisions]]. 300 301 302---- 303 304<div id="Inside"></div> 305<div class="header"> 306<p> 307Next: [[#Copying the history file|Rename by copying]], Previous: [[#The Normal way to Rename|Outside]], Up: [[#Moving and renaming files|Moving files]] |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p> 308</div> 309<div id="Moving-the-history-file"></div> 310==== Moving the history file ==== 311 312This method is more dangerous, since it involves moving 313files inside the repository. Read this entire section 314before trying it out! 315 316<div class="example" style="margin-left: 3.2em"> 317 $ cd $CVSROOT/<var>dir</var> 318 $ mv <var>old</var>,v <var>new</var>,v 319</div> 320 321Advantages: 322 323 324* The log of changes is maintained intact. 325 326 327* The revision numbers are not affected. 328 329Disadvantages: 330 331 332* Old releases cannot easily be fetched from the repository. (The file will show up as <var>new</var> even in revisions from the time before it was renamed). 333 334 335* There is no log information of when the file was renamed. 336 337 338* Nasty things might happen if someone accesses the history file while you are moving it. Make sure no one else runs any of the <small>CVS</small> commands while you move it. 339 340 341---- 342 343<div id="Rename-by-copying"></div> 344<div class="header"> 345<p> 346Previous: [[#Moving the history file|Inside]], Up: [[#Moving and renaming files|Moving files]] |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p> 347</div> 348<div id="Copying-the-history-file"></div> 349==== Copying the history file ==== 350 351This way also involves direct modifications to the 352repository. It is safe, but not without drawbacks. 353 354<div class="example" style="margin-left: 3.2em"> 355 # <span class="roman" style="font-family:serif; font-weight:normal">Copy the RCS file inside the repository</span> 356 $ cd $CVSROOT/<var>dir</var> 357 $ cp <var>old</var>,v <var>new</var>,v 358 # <span class="roman" style="font-family:serif; font-weight:normal">Remove the old file</span> 359 $ cd ~/<var>dir</var> 360 $ rm <var>old</var> 361 $ cvs remove <var>old</var> 362 $ cvs commit <var>old</var> 363 # <span class="roman" style="font-family:serif; font-weight:normal">Remove all tags from <var>new</var></span> 364 $ cvs update <var>new</var> 365 $ cvs log <var>new</var> # <span class="roman" style="font-family:serif; font-weight:normal">Remember the non-branch tag names</span> 366 $ cvs tag -d <var>tag1</var> <var>new</var> 367 $ cvs tag -d <var>tag2</var> <var>new</var> 368 … 369</div> 370 371By removing the tags you will be able to check out old 372revisions. 373 374Advantages: 375 376 377* Checking out old revisions works correctly, as long as you use ‘<code>-r<var>tag</var></code>’ and not ‘<code>-D<var>date</var></code>’ to retrieve the revisions. 378 379 380* The log of changes is maintained intact. 381 382 383* The revision numbers are not affected. 384 385Disadvantages: 386 387 388* You cannot easily see the history of the file across the rename. 389 390 391 392---- 393 394<div id="Moving-directories"></div> 395<div class="header"> 396<p> 397Previous: [[#Moving and renaming files|Moving files]], Up: [[#Adding, removing, and renaming files and directories|Adding and removing]] |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p> 398</div> 399<div id="Moving-and-renaming-directories"></div> 400=== Moving and renaming directories === 401<div id="index-Moving-directories"></div> 402<div id="index-Renaming-directories"></div> 403<div id="index-Directories_002c-moving"></div> 404 405The normal way to rename or move a directory is to 406rename or move each file within it as described in 407[[#The Normal way to Rename|Outside]]. Then check out with the ‘<code>-P</code>’ 408option, as described in [[#Removing directories|Removing directories]]. 409 410If you really want to hack the repository to rename or 411delete a directory in the repository, you can do it 412like this: 413 414 415# Inform everyone who has a checked out copy of the directory that the directory will be renamed. They should commit all their changes, and remove their working copies, before you take the steps below. 416 417 418# Rename the directory inside the repository. 419 420<div class="example" style="margin-left: 3.2em"> 421 $ cd $CVSROOT/<var>parent-dir</var> 422 $ mv <var>old-dir</var> <var>new-dir</var> 423</div> 424 425 426# Fix the <small>CVS</small> administrative files, if necessary (for instance if you renamed an entire module). 427 428 429# Tell everyone that they can check out again and continue working. 430 431 432If someone had a working copy the <small>CVS</small> commands will 433cease to work for him, until he removes the directory 434that disappeared inside the repository. 435 436It is almost always better to move the files in the 437directory instead of moving the directory. If you move the 438directory you are unlikely to be able to retrieve old 439releases correctly, since they probably depend on the 440name of the directories. 441 442 443---- 444 445<div class="header"> 446<p> 447Previous: [[#Moving and renaming files|Moving files]], Up: [[#Adding, removing, and renaming files and directories|Adding and removing]] |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p> 448</div> 449This document was generated on <i>a sunny day</i> using [http://www.nongnu.org/texi2html/ <i>texi2html</i>]. 450