Some people have trouble absorbing a new technology by reading the sort of "top down" approach provided by this book. This section is a very short introduction to Subversion, and is designed to give "bottom up" learners a fighting chance. If you're one of those folks who prefers to learn by experimentation, the following demonstration will get you up and running. Along the way, we give links to the relevant chapters of this book.
If you're new to the entire concept of version control or to the “copy-modify-merge” model used by both CVS and Subversion, then you should read Chapter 2, Basic Concepts before going any further.
The following example assumes that you have 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.
Subversion stores all versioned data in a central repository. To begin, create a new repository:
$ svnadmin create /path/to/repos $ ls /path/to/repos conf/ dav/ db/ format hooks/ locks/ README.txt
This command creates a new directory /path/to/repos which contains a Subversion repository. Make sure that this directory lives on a local disk, not a network share. This new directory mainly contains a collection of Berkeley DB database files. You won't see your versioned files if you peek inside. For more information about repository creation and maintenance, see Chapter 5, Repository Administration.
Next, create a tree of files and directories to import into the repository. For reasons that will be clear later on (see Chapter 4, Branching and Merging), your structure should contain three top-level directories named branches, tags, and trunk:
/tmp/project/branches/ /tmp/project/tags/ /tmp/project/trunk/ foo.c bar.c Makefile …
Once you have a tree of data ready to go, import the data into the repository with the svn import command (see the section called “svn import”):
$ svn import /tmp/project file:///path/to/repos -m "initial import" Adding /tmp/project/branches Adding /tmp/project/tags Adding /tmp/project/trunk Adding /tmp/project/trunk/foo.c Adding /tmp/project/trunk/bar.c Adding /tmp/project/trunk/Makefile … Committed revision 1. $
Now the repository contains this tree of data. Note that the original /tmp/project directory is unchanged; Subversion is unaware of it. (In fact, you can even delete that directory if you wish.) In order to start manipulating repository data, you need to create a new “working copy” of the data, a sort of private workspace. Ask Subversion to “check out” a working copy of the repository's trunk directory:
$ svn checkout file:///path/to/repos/trunk project A project/foo.c A project/bar.c A project/Makefile … Checked out revision 1.
Now you have a personal copy of part of the repository in a new directory named project. You can edit the files in your working copy and then commit those changes back into the repository.
Enter your working copy and edit a file's contents.
Run svn diff to see unified diff output of your changes.
Run svn commit to commit the new version of your file to the repository.
Run svn update to bring your working copy “up-to-date” with the repository.
For a full tour of all the things you can do with your working copy, read Chapter 3, Guided Tour.
At this point, you have the option of making your repository available to others over a network. See Chapter 6, Server Configuration to learn about the different sorts of server processes available and how to configure them.