04.08.2013 Views

Version Control with Subversion - Electrical and Computer ...

Version Control with Subversion - Electrical and Computer ...

Version Control with Subversion - Electrical and Computer ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

stration will get you up <strong>and</strong> running. Along the way, we give links to the relevant chapters of this book.<br />

If you're new to the entire concept of version control or to the “copy-modify-merge” model used by both<br />

CVS <strong>and</strong> <strong>Subversion</strong>, then you should read Chapter 2, Basic Concepts before going any further.<br />

Note<br />

The following example assumes that you have svn, the <strong>Subversion</strong> comm<strong>and</strong>-line client,<br />

<strong>and</strong> svnadmin, the administrative tool, ready to go. It also assumes you are using <strong>Subversion</strong><br />

1.2 or later (run svn --version to check.)<br />

<strong>Subversion</strong> stores all versioned data in a central repository. To begin, create a new repository:<br />

$ svnadmin create /path/to/repos<br />

$ ls /path/to/repos<br />

conf/ dav/ db/ format hooks/ locks/ README.txt<br />

This comm<strong>and</strong> creates a new directory /path/to/repos which contains a <strong>Subversion</strong> repository.<br />

This new directory contains (among other things) a collection of database files. You won't see your versioned<br />

files if you peek inside. For more information about repository creation <strong>and</strong> maintenance, see<br />

Chapter 5, Repository Administration.<br />

<strong>Subversion</strong> has no concept of a “project”. The repository is just a virtual versioned filesystem, a large<br />

tree that can hold anything you wish. Some administrators prefer to store only one project in a repository,<br />

<strong>and</strong> others prefer to store multiple projects in a repository by placing them into separate directories.<br />

The merits of each approach are discussed in the section called “Choosing a Repository Layout”. Either<br />

way, the repository only manages files <strong>and</strong> directories, so it's up to humans to interpret particular directories<br />

as “projects”. So while you might see references to projects throughout this book, keep in mind<br />

that we're only ever talking about some directory (or collection of directories) in the repository.<br />

In this example, we assume that you already have some sort of project (a collection of files <strong>and</strong> directories)<br />

that you wish to import into your newly created <strong>Subversion</strong> repository. Begin by organizing them<br />

into a single directory called myproject (or whatever you wish). For reasons that will be clear later<br />

(see Chapter 4, Branching <strong>and</strong> Merging), your project's tree structure should contain three top-level directories<br />

named branches, tags, <strong>and</strong> trunk. The trunk directory should contain all of your data,<br />

while branches <strong>and</strong> tags directories are empty:<br />

/tmp/myproject/branches/<br />

/tmp/myproject/tags/<br />

/tmp/myproject/trunk/ foo.c<br />

bar.c<br />

Makefile<br />

…<br />

Introduction<br />

The branches, tags, <strong>and</strong> trunk subdirectories aren't actually required by <strong>Subversion</strong>. They're<br />

merely a popular convention that you'll most likely want to use later on.<br />

Once you have your tree of data ready to go, import it into the repository <strong>with</strong> the svn import comm<strong>and</strong><br />

(see the section called “svn import”):<br />

$ svn import /tmp/myproject file:///path/to/repos/myproject -m "initial import"<br />

Adding /tmp/myproject/branches<br />

Adding /tmp/myproject/tags<br />

6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!