CVS to SVN Crossover Guide

Purpose

This document provides an alternate method of learning Subversion. Many users dislike learning new technology via a theoretical "top down" approach, as provided by the Subversion Book. Instead, this document presents Subversion from the "bottom up": it shows a CVS command or task, and then shows the equivalent task in Subversion (along with relevant book links.) It's essentially a re-indexing of topics covered by the book, keyed on CVS tasks.

Table of Contents

Setup

Basic Work Cycle

Examining history

Branching/Tagging/Merging

Other tasks

Repository creation

Create a new repository for holding versioned data.

CVS Subversion
Commands:
$ cvs -d /usr/local/repos init
Explanation:
Creates a new directory repos ready to hold RCS files and config scripts.
Commands:
$ svnadmin create /usr/local/repos
Explanation:
Creates a new directory repos containing BerkeleyDB files and config scripts.
Book References:
Repository Creation and Configuration

Importing data

Populate a new repository with initial data. Assuming that you have a tree of code in the local directory myproj/, and you want to move this tree into the repository.

CVS Subversion
Commands:
$ cd myproj
$ cvs -d /usr/local/repos import myproj/ none start
Explanation:
This copies the contents of the current working directory to a new directory (myproj) in the CVS repository. The CVS repository now contains a directory /myproj/ at the top level.
Commands:
$ svn mkdir file:///usr/local/repos/tags
$ svn mkdir file:///usr/local/repos/branches
$ svn import myproj/ file:///usr/local/repos/trunk
Explanation:
Though not strictly required, we deliberately create /tags and /branches top-level directories in the repository, to hold tags and branches later on. Then we import the contents of the local myproj/ directory into a newly created /trunk directory in the repository.
Book References:
Choosing a repository layout
svn import

Installing a server

Make the repository available to clients via a network.

CVS Subversion
Commands:
(too complex to demonstrate here)
Explanation:
Export the repository via the cvs pserver program. It can be launched by either inetd or a client's ssh remote request.
Commands:
(too complex to demonstrate here)
Explanation:
Export the repository with the Apache 2.0.x server, or via the svnserve program. The latter can run as a standalone daemon, can be launched by inetd, or invoked by a client's ssh remote request.
Book References:
Server configuration

Authenticating to a server

Have a network client prove its identity to a version control server.

CVS Subversion
Commands:
$ cvs -d :pserver:user@host:/repos command
Explanation:
When contacting a repository, the client pre-emptively "pushes" its authentication credentials at the server.
Commands:
$ svn command URL
Password for 'user':  XXXXXXX
Explanation:
The client's authentication credentials are "pulled" from the user interactively, and only when the server deems that a challenge needs to be made. (And contrary to popular belief, the --username and --password options are merely values to be used if the server issues a challenge; they do not "push" the credentials at the server.)
Book References:
Network Model

Browsing a repository

Browse the repository as a filesystem, perusing file contents and history as well (older versions of files or trees.)

CVS Subversion
Commands:
(not possible with commandline client)
Explanation:
Not possible with commandline client. A third-party web server tool such as ViewCVS must be used.
Commands:
$ svn list URL [-r rev] [-v]
$ svn cat URL [-r rev]
Explanation:
The svn list and svn cat commands allow interactive browsing of a repository (and all previous states of a repository) from the commandline. (The --verbose [-v] switch displays full listing information.) If Apache is being used as a Subversion server process (i.e. clients access via http://), then the latest version of the repository can be directly browsed by entering URL into any web browser. Additionally, a third-party web server tool (such as ViewCVS) can be used with Subversion.
Book References:
svn list

Checking out a working copy

Create a workspace on local disk which mirrors a directory in the repository.

CVS Subversion
Commands:
$ cvs -d /usr/local/repos checkout myproj
U myproj/foo.c
U myproj/bar.c
Explanation:
Creates a local directory myproj which is a mirror of the repository directory /myproj.
Commands:
$ svn checkout file:///usr/local/repos/trunk myproj
A  myproj/foo.c
A  myproj/bar.c
Explanation:
Assuming that the original project data was imported into the repository /trunk directory, this creates a local directory myproj which is a mirror of the repository directory /trunk. Standard Subversion convention is to do "mainline" development in /trunk. See branching and tagging sections for more details.
Book References:
Initial Checkout
svn checkout

Seeing locally changed items

Discover which items in the working copy have local modifications or are scheduled for addition/deletion.

CVS Subversion
Commands:
$ cvs status
File: baz.c   Status: Up-to-date
$ cvs update
M foo.c
U bar.c
Explanation:
The cvs status command shows whether a file is locally modified or out of date, including information about working revision and branch info. Unfortunately, because the output is so verbose and hard to read, many users run cvs update instead, which shows a more compact listing of modified files (and of course, it also causes the server to merge changes into your working copy.)
Commands:
$ svn status
M     foo.c
Explanation:
Shows modified files only. Very fast, as it does not use the network. Does not update your working copy, yet still shows a single-line display, much like svn update. To see working revision and branch information, run svn info.
Book References:
Examine Your Changes
svn status

Seeing out-of-date items

Discover which items in the working copy are out-of-date (i.e. newer versions exist in the repository.)

CVS Subversion
Commands:
$ cvs status
File: baz.c   Status: Needs Patch
$ cvs -n update
M foo.c
U bar.c
Explanation:
The cvs status command shows whether a file is locally modified or out of date, including information about working revision and branch info. A less verbose option is to run cvs -n update instead, which shows a compact listing of both out-of-date and locally modified files, without actually updating the working copy.
Commands:
$ svn status -u
M     46     foo.c
M  *  46     bar.c
   *  46     baz.c
Explanation:
Shows modified files (M) as well as out-of-date files (*). Contacts repository, but doesn't modify the working copy. To see working revision and branch information, run svn info.
Book References:
Examine Your Changes
svn status

Scheduling additions or deletions

Schedule a working-copy file or directory to be added or removed from the repository.

CVS Subversion
Commands:
$ touch foo.c
$ cvs add foo.c
cvs server: scheduling file `blah' for addition
cvs server: use 'cvs commit' to add this file permanently
 
$ mkdir new-dir
$ cvs add new-dir
Directory new-dir added to the repository
 
$ rm bar.c
$ cvs rm bar.c
cvs remove: scheduling `bar.c' for removal
cvs remove: use 'cvs commit' to remove this file permanently
 
$ rm -rf old-dir/*
$ cvs rm old-dir
cvs remove: Removing 3bits
Explanation:
Schedules a file or directory for addition or removal to/from the repository. The repository will not be changed until the user runs cvs commit, except for the case of adding a directory, which immediately changes the repository. Also, directories cannot be truly removed from the repository, just emptied out. (cvs update -P will prune empty directories from your working copy.)
Commands:
$ touch foo.c
$ svn add foo.c
A     foo.c
 
$ mkdir new-dir
$ svn add new-dir
A     new-dir
 
$ svn rm bar.c
D     bar.c
 
$ svn rm old-dir
D     old-dir/file1
D     old-dir/file2
Explanation:
Schedules a file or directory for addition or removal to/from the repository. The repository will not be changed until the user runs svn commit. The scheduled operations are shown as A or D by svn status, and svn revert can un-do the scheduling. Directories really can be deleted (though as with all deleted items, continues to exist in history.)
Book References:
Make Changes to Your Working Copy
svn add
svn delete

Copying and moving

Copy or move/rename a file or directory.

CVS Subversion
Commands:
(not possible.)
Explanation:
Not possible, unless an administrator directly mucks with RCS files in the repository. (And in that case, no history records the act of copying or renaming.)
Commands:
$ svn copy foo.c foo2.c
A     foo2.c
 
$ svn copy dir dir2
A     dir2
 
$ svn move bar.c baz.c
A     baz.c
D     bar.c
 
$ svn move dirA dirB
A     dirB
D     dirA/file1
D     dirA/file2
Explanation:
The svn copy command schedules a file or directory for addition to the repository, recording the "source" of the copy. After committing, svn log on the copied item will trace history back through the original copy-source. The svn move command is exactly equivalent to running svn copy, followed by an svn delete on the copy-source: the result is a new item scheduled for addition (with copy-history attached) and the original item scheduled for deletion.
Book References:
Make Changes to Your Working Copy
svn copy
svn move

Finding the beginning of a branch

If you're attempting to merge an entire branch into another, you need to compare the "root" and "tip" of the source branch, and then merge those differences into a working copy of the target branch. Obviously the "tip" of the branch can be represented by using the HEAD keyword. But how do you find the "birth" revision of the source branch?

The easiest solution is to run

   $ svn log -v --stop-on-copy source-branch-URL
   …

This command will display every change ever made to the branch, but --stop-on-copy option will cause the output to stop as soon as detects a copy operation in the branch's history. By definition, then, the very last log entry printed will show the copy being made. It will look something like:

r9189 | joe | 2004-03-22 10:10:47 -0600 (Mon, 22 Mar 2004) | 1 line
Changed paths:
   A /branches/mybranch (from /trunk:9188)

In this case, you would then know to compare revisions 9189 and HEAD of the branch in order to perform the merge:

   $ svn merge -r9189:HEAD source-branch-URL target-branch-WC
   …

Seeing all of a project's tags

Assuming you've been following a consistent policy for creating tag-copies, then this is just a matter of running svn ls on a directory containing your tags. Typically you would run it on the /tags directory in your repository, although you're certainly free to organize this directory in a more complex way, or invent a different convention altogether.

As an example, you can see all of Subversion's tags by running:

   $ svn ls --verbose http://svn.apache.org/repos/asf/subversion/tags
     …
       7739 kfogel              Nov 13 22:05 0.33.0/
       7796 josander            Nov 18 12:15 0.33.1/
       7932 josander            Dec 03 17:54 0.34.0/
       8045 josander            Dec 19 15:13 0.35.0/
       8063 josander            Dec 20 11:20 0.35.1/
       8282 josander            Jan 13 14:15 0.36.0/
       8512 josander            Jan 24 17:31 0.37.0/
       8810 kfogel              Feb 23 03:44 1.0.0/
     …

Seeing the differences between two tags

Just use svn diff in its fully expanded form, which compares any two URLs:

   $ svn diff tagURL1 tagURL2
   …

Seeing logs between two tags

This is a somewhat common practice in CVS, and is doable in Subversion, but requires a little bit more work. Assuming that you've made two tags of /trunk at different points in time, the ultimate goal here is to run

   $ svn log -rX:Y trunkURL

…where X and Y are the revisions from which the two tags were copied. To discover X and Y, you can use the same technique described in the previous section ("finding the beginning of a branch".) Just use the --stop-on-copy option when logging the history of each tag. No commits happen on tag directories, so the following commands should each produce exactly one log entry:

   $ svn log -v --stop-on-copy tag1-URL

   r3520 | joe | 2004-03-12 15:28:43 -0600 (Fri, 12 Mar 2004) | 1 line
   …

   $ svn log -v --stop-on-copy tag2-URL
   a
   r4177 | joe | 2004-03-12 15:28:43 -0600 (Fri, 12 Mar 2004) | 1 line
   …

So in this example, the values of X and Y are 3520 and 4177. Now you can view all /trunk changes between those two points in time:

   $ svn log -r3520:4177 trunkURL
   …

Fixing an incorrect tag

If your tag is a bit off, you can "adjust" it just as people often do in CVS. Simply check out a working copy of the tag directory, make any changes you wish, and commit.

Remember, because branches and tags are directories, they can also be deleted when they're no longer of any use to your project. They'll continue to exist in the repository's history.

Creating/using "modules"

Compare CVS Modules vs. svn:externals.