Cover | Table of Contents | Online Book | Colophon
http://www.collab.net) began
seeking developers to write a replacement for CVS. CollabNet offers a
collaboration software suite called SourceCast, of which one
component is version control. Although SourceCast used CVS as its
initial version control system, CVS's limitations
were obvious from the beginning, and CollabNet knew it would
eventually have to find something better. Unfortunately, CVS had
become the de facto standard in the open source world largely because
there wasn't anything better,
at least not under a free license. So CollabNet determined to write a
new version control system from scratch, retaining the basic ideas of
CVS, but without the bugs and misfeatures.
http://subversion.tigris.org) often has these
packages available for download, posted by volunteers. The site
usually contains graphical installer packages for users of Microsoft
operating systems. If you run a Unix-like operating system, you can
use your system's native package distribution system
(RPMs, DEBs, the ports tree, etc.) to get
Subversion.
svn, Subversion's command-line
client program.svn,
the Subversion commandline client, and svnadmin,
the administrative tool, ready to go. It also assumes that your
svn client has been compiled against Berkeley DB.
To verify this, run svn —version and make
sure the ra_local module is available. Without
this module, the client cannot access file://
URLs.$ svnadmin create /path/to/repos $ ls /path/to/repos conf/ dav/ db/ format hooks/ locks/ README.txt
/tmp/project/branches/
/tmp/project/tags/
/tmp/project/trunk/
foo.c
bar.c
Makefile
...
svn help. The Subversion command-line client is
self-documenting—at any time, a quick svn help
<subcommand> will describe the syntax, switches, and
behavior of the subcommand.svn import
to import a new project into a Subversion repository. While this is
most likely the very first thing you will do when you set up your
Subversion server, it's not something that happens
very often. For a detailed description of import, see Section 3.7.2 later in this chapter.--revision
(-r) switch plus the revision you want (svn
—revision REV), or you can specify a range by
separating two revisions with a colon (svn —revision
REV1:REV2). Subversion lets you refer to these revisions by
number, keyword, or date.svn help. The Subversion command-line client is
self-documenting—at any time, a quick svn help
<subcommand> will describe the syntax, switches, and
behavior of the subcommand.svn import
to import a new project into a Subversion repository. While this is
most likely the very first thing you will do when you set up your
Subversion server, it's not something that happens
very often. For a detailed description of import, see Section 3.7.2 later in this chapter.--revision
(-r) switch plus the revision you want (svn
—revision REV), or you can specify a range by
separating two revisions with a colon (svn —revision
REV1:REV2). Subversion lets you refer to these revisions by
number, keyword, or date.$ svn commit --message "Corrected number of cheese slices." Sending sandwich.txt Transmitting file data . Committed revision 3.
--revision switch, and are
resolved into specific revision numbers by
Subversion:
HEAD (latest revision) of the
Subversion repository that you specify on the command
line:
$ svn checkout http://svn.collab.net/repos/svn/trunk A trunk/subversion.dsw A trunk/svn_check.dsp A trunk/COMMITTERS A trunk/configure.in A trunk/IDEAS ... Checked out revision 2499.
$ svn checkout http://svn.collab.net/repos/svn/trunk/doc/book/tools A tools/readme-dblite.html A tools/fo-stylesheet.xsl A tools/svnbook.el A tools/dtd A tools/dtd/dblite.dtd ... Checked out revision 3678.
svn copy or svn
move instead of the copy and move commands provided by your
operating system. We'll talk more about svn
copy and svn move later in this chapter.svn update
svn add
svn delete
svn copy
svn move
svn status
svn diff
svn revert
svn merge
svn resolved
svn commit
svn update to bring your working copy in sync with
the latest revision in the repository.$ svn update U foo.c U bar.c Updated to revision 2.
svn update a bit more. When the server
sends changes to your working copy, a letter code is displayed next
to each item to let you know what actions Subversion performed to
bring your working copy up-to-date:U foo
Updated
(received changes from the server).A foo
Added to your working copy.D foo
svn log
svn diff
svn cat
svn list
svn log command. svn log
will provide you with a record of who made changes to a file or
directory, at what revision it changed, the time and date of that
revision, and, if it was provided, the log message that accompanied
the commit.$ svn log ------------------------------------------------------------------------ r3 | sally | Mon, 15 Jul 2002 18:03:46 -0500 | 1 line Added include lines and corrected # of cheese slices. ------------------------------------------------------------------------ r2 | harry | Mon, 15 Jul 2002 17:47:57 -0500 | 1 line Added main( ) methods. ------------------------------------------------------------------------ r1 | sally | Mon, 15 Jul 2002 17:40:08 -0500 | 1 line Initial import ------------------------------------------------------------------------
svn
cleanup does: it searches your working copy and runs any
leftover logs, removing locks in the process. If Subversion ever
tells you that some part of your working copy is locked, then this is
the command that you should run. Also, svn status
will display an L next to locked items:$ svn status L somedir M somedir/foo.c $ svn cleanup $ svn status M somedir/foo.c
svn
import command is a quick way to copy an unversioned tree
of files into a repository, creating intermediate directories as
necessary.$ svnadmin create /usr/local/svn/newrepos $ svn import mytree file:///usr/local/svn/newrepos/some/project Adding mytree/foo.c Adding mytree/bar.c Adding mytree/subdir Adding mytree/subdir/quux.h Committed revision 1.
$ svn ls file:///usr/local/svn/newrepos/some/project bar.c foo.c subdir/
svn merge command. This command, it turns out, is
a very close cousin to the svn diff command (which
you read about in Chapter 3). Both commands are
able to compare any two objects in the repository and describe the
differences. For example, you can ask svn merge, and
this section describes the most common scenarios.svn merge in this scenario? Remember
that this command compares two trees, and applies the differences to
a working copy. So to receive the changes, you need to have a working
copy of the trunk. We'll assume that either you
still have your original one lying around (fully updated), or that
you recently checked out a fresh working copy of
/calc/trunk.svn merge operates
like svn diff, comparing the latest trunk and
branch trees will not merely describe the set of
changes you made to your branch. Such a comparison shows too many
changes: it would not only show the addition of your branch changes,
but also the removal of trunk changes that never
happened on your branch.svn log on
your branch, you can see that your branch was created in revision
341. And the final state of your branch is simply a matter of using
the HEAD revision. That means you want to compare
revisions 341 and HEAD of your branch directory,
and apply those differences to a working copy of the trunk.svn switch command
transforms an existing working copy into a different branch. While
this command isn't strictly necessary for working
with branches, it provides a nice shortcut to users. In an earlier
example, after creating your private branch, you checked out a fresh
working copy of the new repository directory. Instead, you can simply
ask Subversion to change your working copy of
/calc/trunk to mirror the new branch location:$ cd calc $ svn info | grep URL URL: http://svn.example.com/repos/calc/trunk $ svn switch http://svn.example.com/repos/calc/branches/my-calc-branch U integer.c U button.c U Makefile Updated to revision 341. $ svn info | grep URL URL: http://svn.example.com/repos/calc/branches/my-calc-branch
svn switch
command also takes a --revision
(-r) option, so you need not always move your
working copy to the tip of the branch.svn switch to move only that subdirectory to the
branch. (Sometimes users will switch just a single working file to
the branch!) That way, they can continue to receive normal trunk
updates to most of their working copy, but the switched portions will
remain immune (unless someone commits a change to their branch). This
feature adds a whole new dimension to the concept of a mixed working
copy—not only can working copies contain a mixture of working
revisions, but a mixture of repository locations as well.release-1.0. And they want to make snapshots
of smaller subdirectories of the filesystem. After all,
it's not so easy to remember that release-1.0 of a
piece of software is a particular subdirectory of revision 4822.svn copy
comes to the rescue. If you want to create a snapshot of
/calc/trunk exactly as it looks in the
HEAD revision, then make a copy of it:$ svn copy http://svn.example.com/repos/calc/trunk \
http://svn.example.com/repos/calc/tags/release-1.0 \
-m "Tagging the 1.0 release of the 'calc' project."
Committed revision 351.HEAD revision at th