Tải bản đầy đủ (.pdf) (146 trang)

Pragmatic Guide to Subversion pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (3.41 MB, 146 trang )

Download from Wow! eBook <www.wowebook.com>
What Readers Are Saying About Pragmatic Guide to Subversion
Mike h as been around the block with Subversion and knows the toolset
intimately. Just as importantly, he’ s seen firsthand how it’s used on real
projects. Those two aspects come together in this book with the fundamen-
tals of source control with Subversion, g uided by r eal-world, pragmatic (of
course!) e x p e r i e n c e . As a Subversion user and occasional n oob, this is the
book I w an t t o guide me day to d ay and dig me out of t hose irksome holes.
Jim W e b b e r
Author, REST i n Practice
I really like the organization of the b ook. I f ound Pragmatic Guide to S ub-
version t o be v e r y easy to read, and it really gets the information across in
an engaging w ay. This book is c lear, concise, and comprehensive. It’s an
indispensable reference for anyone wo rk i ng with Subversion.
Ian Bourke
Independent software developer, UK
A good digest of S ubversion’s capabilities. The author’ s writing style is
terse yet conversational, and the b ook progressed nicely from basic t opics
to those more adv anced. Overall, I think the book is a n e x c e l l e n t follow-up
to Pragmatic V e r s i o n Control Using Subversion.
Graham Nash
Retlang, Message-based concurrency in .NET
This is a book wo rth ha ving since the “full” Pragmatic Subversion book i s
too big for e v e r y d e veloper on a team t o read. I was a fan of Mike’ s original
Subversion book, a nd he’s carried on the style into this p ocket reference.
This is a book I r ecommend.
Mike Roberts
Senior software e ngineer, DRW T r a d i n g Group
Pragmatic Guide to Subversion has e v e r y t h i n g I needed t o get u p and run-
ning with SVN on my Mac. Being ne w to Mac OS X, it w as a welcome s ur-
prise to have e x a m p l e s in multiple operating systems.


Michael Raczynski
Software a rchitect, Canada
Download from Wow! eBook <www.wowebook.com>
Pragmatic Guide to Subversion
Mike Mason
The P ragmatic Bookshelf
Raleigh, North Carolina Dallas, T e x a s
Download from Wow! eBook <www.wowebook.com>
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in this b ook, and The P ragmatic Pro-
grammers, LLC was aw a re of a trademark claim, the d esignations have been printed in initial
capital letters or in a ll capitals. The P ragmatic Starter Kit, T he Pragmatic P rogrammer, Pragmatic
Programming, Pragmatic Bookshelf and the linking g device are trademarks o f The Pragmatic
Programmers, LLC.
Every precaution wa s taken in the preparation o f this book. However, the publisher assumes no
responsibility f or errors or o missions, or for damages that may result from the use o f information
(including p rogram listings) contained h erein.
Our Pragmatic courses, workshops, and other products can help you and your team create better
software and have more fun. F o r more information, as well as the latest Pragmatic titles, please
visit u s at h ttp://www.pragprog.com.
The team that p roduced this b ook includes:
Editor: Jackie Carter
Indexing: Potomac I ndexing, LLC
Copy edit: Kim W i m p s e t t
Layout: Steve Peter
Production: Janet Furlow
Customer support: Ellie Callahan
International: Juliet Benda
Copyright
©

2010 Pragmatic P rogrammers, LLC.
All r ights reserved.
No part of this publication m ay b e reproduced, stored in a retrieval s ystem, or transmitted, in an y
form, or by any means, electronic, mechanical, photocopying, recording, or o therwise, without the
prior consent of the publisher .
Printed in the United States of America.
ISBN-10: 1-934356-61-1
ISBN-13: 978-1-934356-61-6
Printed o n acid-free p aper .
P1.0 printing, October 2 010
V e r s i o n : 2010-11-12
Download from Wow! eBook <www.wowebook.com>
Contents
Acknowledgments 8
Introduction 9
Who I s This Book F o r ? . . . . . . . . . . . . . . . . . . . . 10
How to Read This Book . . . . . . . . . . . . . . . . . . . . 11
Subversion V e r s i o n s . . . . . . . . . . . . . . . . . . . . . . 12
Online Resources . . . . . . . . . . . . . . . . . . . . . . . 12
I Getting Started 13
T a s k 1. Installing a Command-Line Client 16
T a s k 2. Installing a Graphical Client on W i n d o w s 18
T a s k 3. Installing a Graphical Client on Mac OS X 20
T a s k 4. Creating a Local Repository 22
T a s k 5. Creating an Empty Pr oject 24
T a s k 6. Creating a Project from a n Existing S ource T r e e 26
II W o r k i n g with Subversion 28
T a s k 7. Checking Out a W o r k i n g Copy 32
T a s k 8. Seeing What Y o u ’ v e Changed 34
T a s k 9. Seeing What Y o u ’ v e Changed Using T o r t o i s e 36

T a s k 10. Seeing What Y o u ’ v e Changed Using Cornerstone 38
T a s k 11. Committing Changes 40
T a s k 12. Adding Files and Directories 42
Download from Wow! eBook <www.wowebook.com>
CONTENTS 6
T a s k 13. Removing Files and Directories 44
T a s k 14. Moving a nd Renaming Files and Directories 46
T a s k 15. Reverting W o r k i n g Copy Changes 48
T a s k 16. Ignoring Files 50
III W o r k i n g with a T e a m 52
T a s k 17. Updating to the Latest Revision 56
T a s k 18. Handling Conflicts 58
T a s k 19. Handling Conflicts Using T o r t o i s e 60
T a s k 20. Handling Conflicts Using Cornerstone 62
IV Using the History 64
T a s k 21. V i e w i n g the Log 66
T a s k 22. Detective W o r k with svn blame 68
T a s k 23. Reverting a Committed Revision 70
V Branching, Merging, and T a g g i n g 72
T a s k 24. Creating a Branch 78
T a s k 25. Switching t o a Branch 80
T a s k 26. Merging Changes fr om T r u n k to Branch 82
T a s k 27. Using Change T r a c k i n g 84
T a s k 28. T a g g i n g a Release 86
VI File Locking 88
T a s k 29. Enabling File Locking 9 2
T a s k 30. Obtaining a Lock 94
T a s k 31. Releasing a Lock 96
T a s k 32. Breaking Someone Else’s Lock 98
Report erratum

this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
CONTENTS 7
VII Setting Up a Server 100
T a s k 33. Installing Subversion S erver 104
T a s k 34. Creating a Repository 106
T a s k 35. Installing Subversion S erver on W i n d o w s 108
T a s k 36. Using Third-Party Subversion Hosting 110
T a s k 37. Migrating a CVS Repository 112
T a s k 38. Backing Up a nd Restoring 114
T a s k 39. P e r f o r m i n g Full W e e k l y Backups 1 16
T a s k 40. P e r f o r m i n g Incremental Daily Backups 118
T a s k 41. Securing a Repository 120
T a s k 42. Using Repository Hooks 122
VIII Advanced T o p i c s 124
T a s k 43. W o r k i n g with Properties 126
T a s k 44. Using Externals 128
T a s k 45. Organizing Multiple Projects 130
T a s k 46. Storing Third-Party Code 132
T a s k 47. W o r k i n g Directly with t he Repository 134
T a s k 48. Using P at ch Files 136
A Bibliography 1 38
Index 139
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
Acknowledgments
Every book—even a shorter one like this Pragmatic Guide—represents an
incredible amount of w ork by a large group of p eople. As a n author , my con-
tribution is only a f raction of the ef fort that’s required to get a book into the

hands of readers, and I’d like to thank e v e r y o n e else involved.
First and foremost, I’d like to thank my f amily for supporting me while writ-
ing another book. I’m a ne w d ad with a young son at home, and despite my
best efforts to write faster, our daughter arrived too before I finished the book.
So, to my wife, Michelle, and her mom, P a t , thanks for taking care o f the kids
and l etting me have those Sundays in the office writing the book. T o Ben and
Natalie, t hanks for not being too upset when “Daddy wo rki ng! ” I promise to
always come home.
Next, the Pragmatic Guide series idea came from T r a v i s Swicegood, a uthor of
the e x c e l l e n t Pragmatic V e r s i o n Control Using Git [Swi08]. I really liked the
idea of a “get up to speed fa st ” Subversion book, so thank you, T r a v i s . The
folks at Pragmatic Bookshelf were super-awesome to wor k with as usual,
although the operation i s a lot bigger t han when I did the original Subversion
book fi v e years ago. T o Jackie Carter, my editor, thanks for ke ep in g me on
track and (nicely) pushing me to finish. I always felt that you had lots of time
for me, and the book is much better as a result. T o Dave and Andy , thanks
for b u i l d i n g a nontraditional publishing company that creates great books and
gives authors a good d eal.
A small army of people helped with the technical content in the book. T o
my reviewers, Rob Baillie, Ian Bourke, K e v i n Gisi, Leesa Hicks, Michael
Raczynski, Mike Roberts, and Graham Nash, thank you v e r y much indeed.
Y o u r feedback has made this book better, and your encouraging wo r ds helped
me finish the writing. T o my fellow ThoughtWorks authors, especially Martin
F o w l e r and Jonathan McCracken, thank you for being a sounding board while
I wor ked on the book.
Finally , I’d like to thank you, the reader, for choosing this book. I hope you
enjoy reading it—I certainly enjoyed writing i t.
Download from Wow! eBook <www.wowebook.com>
Intr oduction
Subversion is a wildly popular open source v e r s i o n control system, a v a i l -

able for free o v e r the Internet. Subversion is widely considered the de f acto
standard
1
for v e r s i o n control tools, e v e n though such a thing is difficult to
measure, and as a developer, you are likely to encounter Subversion as part of
your w ork .
Subversion is a mature, fully f eatured system that is commonly used by both
commercial and open source development teams. Y o u can b u y commercial
support and consulting services to help you install, configure, and use Sub-
v e r s i o n . If you don’t wa nt the hassle of running a Subversion server, you can
get a third party t o do it for you, a t a low cost o r e v e n for f ree.
Subversion i s a centralized v e r s i o n control system, meaning that i t uses a cen-
tral server t o store files and enable team collaboration. Clients can wo rk dis-
connected from the network—on an airplane, for e x a m p l e — a n d need a net-
wor k connection only if they a ctually wan t to commit changes to the server.
This traditional centralized model assumes that development teams have r ea-
sonable network connectivity to the server. In contrast, some newer decen-
tralized v e r s i o n control systems use a model where each user acts kind of like
a server. Users can swap changes between each other without needing a cen-
tral server. Most organizations will be fine with the centralized model used
by Subversion, b u t it’s wor th being a w a r e that other collaboration styles are
possible.
Subversion is popular because it has all the features that programmers need
and very few e x t r a bells and whistles. It just d oes v e r s i o n control, and it does
it well.
Subversion can track vers i o n information for directories and metadata, a s well
as files. T r e a t i n g directories as first-class objects means that Subversion can
track history across directory moves a nd renames, unlike some older v e r s i o n
1. Determining the ex a ct market share for Subversion is difficult, b u t several online polls
rate S ubversion more popular than any other ve r si on control tool. Martin Fow l er suggests that

within the Agile/XP community , only Subversion, Git, and Mercurial would be recommended:
http://martinfowler .com/bliki/VersionControlTools.html.
Download from Wow! eBook <www.wowebook.com>
WHOIS THISBOOKFOR? 10
control systems. Every file and directory c an have arbitrary metadata associ-
ated with i t using Subversion properties.
Committing a change is atomic, similar to committing to a database. Either
the whole commit succeeds or is rolled back; other users never see a half-
finished commit. As part of the atomic commit process, Subversion groups
all your changes into a r e v i s i o n (sometimes called a c h a n g e s e t ) and assigns
a r e v i s i o n number to the change, unlike older systems that apply a revision
number to each individual file. By grouping changes to multiple files into
a single logical unit, developers are able to better organize and track their
changes.
Subversion has cheap branches and tags that can be created almost instantly.
Branches are used to distinguish different lines of development, most com-
monly to separate code that is in production vs. code that is being activ ely
developed. T a g s are used t o “mark” the state of the code at a particular point
in time so that state can be re-created later. Subversion also supports merge
tracking, which helps automatically merge changes between b ranches.
Subversion is a truly multiplatform tool. Y o u can run Subversion on W i n -
dows, Linux, OS X, and many other flav ors of Unix. Each of these operating
systems is considered a first-class platform by the Subversion developers, and
you can run a production-strength server on any of them. A Subversion client
can talk to a Subversion server e v e n if the client and server are running on
different operating systems. This is good news for anyone trying to fit Sub-
v e r s i o n into their e x i s t i n g infrastructure. F o r those e v a l u a t i n g Subversion, the
wide choice of o perating system makes t hings much e asier since you can run
a server on pretty much any spare machine.
Who Is This Book For?

Most developers have at least some e x p e r i e n c e with a source control tool and
are e x p e c t e d to fluidly switch between tools depending on where they are
wor k in g . This book w as written to bridge the gap between knowing some-
thing about v e r s i o n control and knowing about Subversion specifically .
Pragmatic Guide to Subversion will quickly get you up to speed on Subver-
sion. W e don’t spend a lot of time covering the philosophy of v e r s i o n control
or trying to persuade you i t’s a g ood idea to store your files somewhere safe.
If you are interested in a broader discussion of v e r s i o n control concepts and
some of the reasoning behind what we do, check out Pragmatic V e r s i o n Con-
trol Using Subversion [Mas06],
2
my previous book.
2. />Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
HOW TOREADTHISBOOK 1 1
How to Read This Book
This b ook is organized into parts t hat each cov er a portion of the Subversion
software management “life c y c l e .” Each part of the book contains some intro-
ductory pages discussing how Subversion handles particular concepts. Y o u
should read the introductions to get a feel for the o v e r a l l concepts and how
e v e r y t h i n g ties together, b u t after that, feel free to jump straight to a p articular
task. If you are new to source control, it’s perfectly OK to read the book in
order—everything will make sense and give you a good grounding in Subver-
sion concepts.
The book is l aid out as double-page spreads for each task, with a discussion
of the task on the left page and the actual steps to achieve the task on the right
page. This w ork s naturally for the printed book, b u t many readers will be
reading a digital ver s i o n . If y ou have the screen space for it, try s etting your
reader t o show two pages side by side to e nhance your reading e x p e r i e n c e .

The parts o f the book a re organized as follows:
• P a r t I: Getting Started covers core Subversion concepts such as the
client, server , repository, and wor kin g copies. Y o u will learn how to
choose and install a Subversion client, how to set up a local repository,
and h ow to import your ex i s t i n g code into Subversion.
• P a r t II: W o r k i n g with Subversion discusses daily wo r kfl ow when using
Subversion. Y o u ’ l l learn how to c heck out from a repository, ex a m i n e
or undo your changes, and commit to the repository.
• P a r t III: W o r k i n g with a T e a m covers how to use S ubversion in a team
setting, how to stay in sync with your team, and how to resolve con-
flicts.
• P a r t IV: Using the History shows you Subversion’ s powerful history
tools so you can understand changes made to your source tree and who
made them. I n some cases, you might wa nt to undo changes that have
been committed t o the repository—this part shows you how.
• P a r t V : Branching, Merging, and T a g g i n g tackles one of t he more com-
plex t opics in source control. Using branches and tags, you can r eliably
release software to production and support it going forward.
• P a r t VI: F i l e Locking covers Subversion’ s optional file locking fea-
tures, which is useful if your repository contains unmergeable files
such as spreadsheets or graphics.
• P a r t VII: Setting Up a Server shows you how to install a Subversion
server on Linux or W i n d o w s , including securing and backing up the
server . I f you’d l ike to use t hird-party hosting instead of running your
o w n server, we discuss h ow to do this too.
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
SUBVERSIONVERSIONS 12
• P a r t VIII: Advanced T o p i c s discusses Subversion features that you

might not need e v e r y day b u t that will be important maybe once or
twice when you set up a project. Included here is information on how
to store multiple projects in a single Subversion repository and how to
store t hird-party c ode in y our o w n repository.
Subversion V e r s i o n s
Subversion is developed by a team of programmers collaborating o v e r the
Internet. It’ s open source, and the Subversion team regularly releases new
v e r s i o n s . Major v e r s i o n s are given numbers such as 1.6 or 1.7, with patch and
b u g fix releases g etting numbers l ike 1.6.3, 1.7.1, and so on.
In general, you should a lways use the ne west release of Subversion, because
new features, b u g fixes, and performance improvements are continually being
made by the Subversion de velopers. New major v e r s i o n s are always backward
compatible with older servers and w ork ing copies—so client v e r s i o n 1.5.x
will w ork with server ve r s i o n 1.6.x—but the opposite is not a lways true.
Always u pgrade a ll the clients o n a computer a t the same t ime. Fo r e x a m p l e ,
if you have both the command-line client and a graphical client and you w an t
to upgrade to Subversion 1.7, upgrade both the command-line and graphi-
cal clients at the same time. If you don’t do this, one or other of the clients
might complain about the wor kin g copy being in a new f ormat that they don’t
understand.
In general, it’ s always safe to upgrade a Subversion client, b u t a Subversion
server requires more attention. Y o u should a lways ensure y ou ha ve a reposi-
tory backup before doing a server upgrade and that you have tested that the
backup restores correctly .
Online Resources
All Pragmatic books have an online component. Y o u can find t he home p age
for t his book here:
/>From here you can download code and the e x a m p l e mBench project used
throughout the book, view the book’s errata, and chat with the author and
other readers in a dedicated online forum.

Subversion is a mature open source system, and there is a lot of community
support for it. A web search will usually turn up loads of e x t r a information
about a topic, most of which is exce l l e n t and high quality. Don’t be a fraid to
look beyond the tasks in t his book and e x p l o r e for yourself.
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
P a r t I
Getting S tarted
Download from Wow! eBook <www.wowebook.com>
GETTINGST A R T E D 14
T o use Subversion, y o u need a server and a client. The server stores
files inside a repository and m a k e s the repository available o v e r a
networ k, either a LAN or the Internet. The client talks to the server
and creates a w o r k i n g copy of the files from the repository. User s
m a k e changes to their files and then commit the changes to the
repository whereother members of their team can see them.
internet
repository
Alice
Bill
Subversion can secure network connections using SSL, the same
technology used to protect credit card information online, or SSH,
the secure shell used to administer Unix m a c h i n e s across the Inter-
net. Subversion can store user credentials in a simple password file
or integrate with an existing store such as Active Directory or LDAP.
Most users w o n ’ t need to w o r r y about administering a Subversion
ser ver, since y o u can easily use a third-party hosting provider o v e r
the Internet or get y o u r company’s server operations team to provi-
sion a Subversion server. If y o u do need to run a server y o u r s e l f , it’s

pretty easy; see T a s k 33, Installing Subversion Server, on page 104 f o r
more details.
Subversion w a s d esigned to be easily extended, so a wide r a n g e
of different clients are available. The basic command-line client is
available f o r most operating systems and will perform all the differ-
ent Subversion functions admirably—you might never need more
than the command-line client. For some operations, it’s nice to have
a GUI to m a k e things easier, so a wide r a n g e of graphical Subver-
sion clients are also available. Doing check-ins, merges, and history
bro wsing can particularly benefit from a GUI.
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
GETTINGST A R T E D 15
For tasks in this book, w e are using the command-line client on
Ubuntu Linux. The client is v e r y similar on Windows and Mac, and
all the command-line examples will w o r k on all three operating sys-
tems. W e ’ v e chosen the T o r t o i s e S V N graphical client f o r Windows
and the Cornerstone graphical client f o r Mac OS X. All of the tasks in
the book include instructions on how to do the job using the graph-
ical clients as w e l l as the command-line client.
If y o u are using an integrated development environment (IDE) such
as IntelliJ, Eclipse, or Xcode, y o u ’ l l find that it supports Subversion
out of the box. Y o u can update w o r k i n g copies, fix conflicts, commit
changes, and view history without leaving the IDE. Other IDEs such
as Visual Studio require a plug-in to w o r k with Subversion, but once
y o u ’ v e installed the plug-in, y o u can w o r k with Subversion seam-
lessly. If y o u ’ r e using an IDE, it’s definitely w o r t h checking out its sup-
port f o r Subversion. Good IDE integr ation f o r y o u r source control tool
can be a significant productivity enhancement.

Covered in this part:
• First y o u ’ l l need to install a Subversion client. If y o u ’ r e on Linux
or prefer a command-line client, refer to T a s k 1, Installing a
Command-Line Client, on the next page. Windows users should
refer to T a s k 2, Installing a Graphical Client on Windows, on
page 18. Mac users should read T a s k 3, Installing a Graphical
Client on Mac OS X, on page 20.
• If y o u don’t have a Subversion repository already set up, T a s k
4, Creating a Local Repository, on page 22 will show y o u how
to set up a local file repository f o r learning Subversion.
• Once y o u have a Subversion repository in place, refer to T a s k
5, Creating an Empty Project, on page 24 to start off with a
blank project in y o u r repository.
• If y o u already have source code that y o u ’ d like to store in
Subversion, T a s k 6, Creating a Project from an Existing Source
T r e e , on page 26 shows y o u how to import y o u r existing source
code into Subversion.
Let’s jump rightinto installing Subversion.
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
INSTALLINGA COMMAND-LINECLIENT 16
1
Installing a Command-Line Client
W e recommend installing the command-line client e v e n if you intend to do
most of your w ork with a graphical client. It’s useful t o have the basic
functionality a v a i l a b l e as a fallb ac k, in case you can’t get the GUI t o do what
you wa nt.
Installing t he client o n W i n d o w s is fai rl y straightforward; just double-click
the installer f rom CollabNet, and it will set e v e r y t h i n g up for you. Y o u can

get the W i n d o w s command-line client from other distributors than
CollabNet, b u t the installers generally aren’t a s friendly.
Installing Subversion on the Mac i s somewhat complicated because you have
several options. Depending on which release of OS X you’ re using, you may
already hav e the command-line Subversion client. Snow Leopard comes
with Subversion 1.6, Leopard comes with Subversion 1.4, and older releases
of OS X d on’t come with Subversion at a ll. If you’ re using a nything older
than Snow Leopard, you should upgrade to the latest release of Subversion.
If you have MacPorts or Fink installed on your system, then you can use their
package managers to install Subversion. I f you h aven’t heard of these t ools,
don’t w or r y; they’ re just a c onvenient wa y to get Unix t ools on the Mac.
Subversion is a v a i l a b l e as p art of the official Ubuntu distribution, so it might
already b e installed o n your s ystem. If not, j ust use the aptpackage manager
to install it. Graphical Subversion clients are a v a i l a b l e for Ubuntu s uch as
Subcommander or RapidSVN, b u t for the p urposes of this book, we’ll stick
to the command-line client.
If you’re more comfortable u sing t he Ubuntu desktop t han the command
line, you can also install S ubversion using Synaptic, Ubuntu’ s graphical
package manager .
Once you’ve installed the S ubversion command-line c lient, you should be
able to open a c ommand prompt and run Subversion commands. T o see what
release of Subversion i s installed, run svn version. Y o u should see
something like this:
prompt> svn version
svn, version 1.6.12 (r955767)
compiled Jun 23 2010, 10:32:19
Make sure y ou have S ubversion 1.6 or ne wer . The w ork i ng copy format
changed in Subversion 1.5 and again in 1.6, and older c lients cannot use the
new formats.
Report erratum

this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
INSTALLINGA COMMAND-LINECLIENT 17
Install the Windows command-line client from CollabNet.
V i s i t CollabNet,
3
and d ownload the command-line client. Once it’s
downloaded, double-click the fi le to start t he installer. If you’re not
interested in r unning a Subversion server, uncheck the svnserve and
Apache options during the install.
Install the M ac command-line client from CollabNet.
V i s i t CollabNet,
4
and d ownload its universal binaries f or OS X. After you’ ve
run t he installer, add the following line t o ~/.profile:
export PATH=/opt/subversion/bin:$PATH
If you’re using MacPorts, you can use it to install Subversion:
prompt> sudo port install subversion
If you’re using Fink, you can use it to install Subversion:
prompt> sudo fink install svn-client
Install the Ubuntu client.
prompt> sudo apt-get update
prompt> sudo apt-get install subversion
Alternatively , click System > Administration > Synaptic P a c k a g e Manager
to start Synaptic. T y p e subversion into the search box to show just
Subversion-related packages. Click the box ne xt to t he subversion package,
and t hen select “Mark for installation.” Choose t o mark any other p ackages
that are r equired. Click the Apply b u t t o n to install t he Subversion p ackages.
Related T a s k s
• T a s k 2, Installing a Graphical Client o n W i n d o w s , on the n ext page

• T a s k 3, Installing a Graphical Client o n Mac OS X, on page 20
• T a s k 33, Installing Subversion Server, on page 104
3. />4. lab .net/downloads/community/
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
INSTALLINGA GRAPHICALCLIENTONWINDOWS 18
2
Installing a Graphical Client on
W i n dow s
T o r t o i s e S V N is an e x c e l l e n t Subversion client f or W i n d o w s that integrates
directly i nto W i n d o w s Explorer. Once T o r t o i s e is installed, you can
right-click anywhere in a W i n d o w s Explorer window a nd get
context-sensitive Subversion options. If y ou right-click in a d irectory that
isn’t a Subversion w o rk i ng copy, T o r t o i s e will offer to l et you check it out
from a repository . If you right-click a directory that is a w ork i ng copy,
T o r t o i s e will o ffer to l et you u pdate or c ommit. If y ou right-click a file inside
a wor kin g copy , T o r t o i s e will offer to s how history for the fi le, a nd so on.
Throughout the rest of t he book, we’ll use a shorthand to d enote choosing
T o r t o i s e menu options, rather than showing screenshots all the time. T o
indicate t hat you should right-click to g et the context menu a nd then click
T o r t o i s e S V N and then Show Log, we will use the a bbreviation
T o r t o i s e S V N > Show Log.
T o r t o i s e shows its context-sensitive options b oth immediately on the context
menu and within the T o r t o i s e S V N flyout menu. T o r t o i s e lets you move
frequently used operations from t he flyout t o the context menu so you can
save yourself a click or two. T o do t his, choose T o r t o i s e S V N > Settings, and
then select Context Menu. Select the box n ext to each o peration that you’ d
like a v a i l a b l e directly o n the context menu.
T o r t o i s e needs a S ubversion repository in o rder t o do anything useful. If you

have a repository already set up, you just need to know the repository URL,
and y ou can get going. If you are trying Subversion f or yourself and need t o
set up a local repository for testing, see T a s k 4, Creating a Local Repository,
on page 22.
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
INSTALLINGA GRAPHICALCLIENTONWINDOWS 19
Install the T o r t o i s e graphical client.
V i s i t tortoisesvn.net,
5
and d ownload T o r t o i s e S V N . T o r t o i s e is integrated
with W i n d o w s Explorer, so y ou should reboot your system once the installer
finishes.
Once it’s installed, you can right-click inside any W i n d o w s Explorer window
to get a context-sensitive T o r t o i s e S V N menu.
Related T a s k s
• T a s k 1, Installing a Command-Line Client, on page 16
• T a s k 33, Installing Subversion Server, on page 104
5. />Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
INSTALLINGA GRAPHICALCLIENTONMAC OSX 20
3
Installing a Graphical Client on Mac
OS X
Cornerstone i s one of several Subversion clients a v a i l a b l e for the Mac. I t has
a nice, clean interface a nd a similar feel to other OS X a pplications.
Cornerstone i s commercial software, so y ou need to b u y a license to use it
longer than its free 14-day trial period.

The Cornerstone window has several s ections. Along the top is a b u t t o n bar
with icons f or the most common Subversion operations. T o t he left is a
column containing the working copy source list a nd the r e p o s i t o r y sour ce
list. In the center i s the main wo rk i ng window , which c an show a working
copy browser, a commit v iew, and a range of other information depending on
what you currently have selected. T o the right is the inspector, which shows
more detail about t he currently selected item.
If you already know the URL f or the r epository you wan t to access, click t he
Add Repository b u t t o n or click the small + b u t t o n at the top of t he
repository source list. Most repositories will be either HTTP or SVN Server;
ask y our administrator if y ou’re not sure. When adding a r epository, it’s best
to omit t he trunk directory from the end o f the URL so that you c an see the
top-level directories a nd w or k with t hem.
If you don’t know the URL f or your repository, you should ask the person in
charge of y our project. If t hat person is you, use the i nstructions in T a s k 5,
Creating a n Empty Project, on page 24 to set up your project. If you’d like to
set up a local repository to get going quickly, see T a s k 4, Creating a Local
Repository, on page 22.
Adding a r epository to the repository source list doesn’t a ctually copy any
files to your computer; we’ll do that in T a s k 7, Checking Out a W o r k i n g
Copy, on page 32. The r est of the Cornerstone e x a m p l e s in this book assume
you ha ve added the Subversion repository f or your project.
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
INSTALLINGA GRAPHICALCLIENTONMAC OSX 21
Install the Cornerstone graphical client.
V i s i t the Cornerstone website,
6
and d ownload Cornerstone. Double-click the

disk image, a nd drag the Cornerstone application i nto your Applications
folder.
When running Cornerstone, y ou’ll be greeted with the main window , as
shown here:
Related T a s k s
• T a s k 1, Installing a Command-Line Client, on page 16
• T a s k 33, Installing Subversion Server, on page 104
6. />Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
CREATINGA LOCALREPOSITORY 22
4
Creating a Local Repository
Most p eople using Subversion don’t need to w or r y about c reating or
maintaining a r epository since it’s an administrative task usually performed
by a server administrator or Unix guru. If you don’t h ave access to o ne of
these people or i f you’d like to e x p e r i m e n t with your o w n repository, you
can u se what’ s called a local r e p o s i t o r y .
A local repository needs t o liv e on your hard drive somewhere. F o r
W i n d o w s , this might be a dedicated directory on the C: drive; for Unix and
Mac OS X, i t’s probably somewhere in your home directory. Once you have
created an empty directory, you need to t ell Subversion to initialize a
repository i n that directory . Command-line users should use t he svnadmin
command t o achieve this. T o r t o i s e users should right-click the directory to
initialize a repository. Cornerstone u sers should use t he Cornerstone GUI to
create t he repository.
Once you have initialized the repository, you can s tart using it, b u t you’ll
need to t ell Subversion where to find the r epository. This is where the
repository b ase URL is needed. The base URL for a local repository always
starts with file:// and ends with the path within the file system to get to your

repository directory.
Y o u can turn a local repository i nto a networked repository by running a
Subversion server a nd pointing it at the repository directory. Y o u can find
more details i n T a s k 33, Installing Subversion Server, on page 104.
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
CREATINGA LOCALREPOSITORY 23
Create a base directory f o r the repository, and then initialize it.
prompt> mkdir -p ~/svn/repos
prompt> svnadmin create ~/svn/repos
The base URL for your local repository is file:///home/myuser/svn/repos.
Create a local repository using T o r t o i s e .
Using W i n d o w s Explorer, create a n empty directory for your repository .
Something such a s C:\Subversion\Repos will wo rk.
Right-click i nside the new directory , and choose T o r t o i s e S V N > Create
repository here.
The base URL for your local repository is file:///C:/Subversion/Repos.
Create a local repository using Cornerstone.
Choose File > Add Repository , or click the plus icon in the repository
source list.
Select the File Repository b u t t o n at t he top, a nd click Create a New
Repository. Click the Where drop-down, and choose the folder i n which you
wan t to create your repository. Usually a d edicated svn directory within your
home directory will wo rk.
Enter a repository name in the “ Create as” box. This is the actual directory
where your n e w repository will be stored.
Click the Compatibility drop-down, a nd choose 1.6. Finally , click the Add
b u t t o n to create the local repository.
The base URL for your local repository is file:///Users/myuser/svn/repos.

Related T a s k s
• T a s k 34, Creating a R epository, on page 106
• T a s k 5, Creating an Empty P roject, on t he following p age
• T a s k 36, Using Third-Party Subversion Hosting, on page 110
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
CREATINGANEMPTYPROJECT 24
5
Creating an Empty Project
Most S ubversion users w on ’t often need t o cr eate a project—that’s usually
done by a s ystems administrator or a t hird-party hosting company. If the
project is a lready set up a nd you know the URL, you can j ump to T a s k 7,
Checking Out a W o r k i n g Copy, on p age 32.
Subversion uses directories as its basic unit of organization, d i viding t he
repository i nto different projects. By c on v ention, all Subversion projects
have trunk, tags, and branches directories directly within the project’ s root
directory. If you had two projects, Kithara and Sesame, you w o u l d end up
with the following directory structure:
• /Kithar a/trunk
• /Kithar a/tags
• /Kithar a/branches
• /Sesame/trunk
• /Sesame/tags
• /Sesame/branches
The trunk directory is where all the main development action h appens and is
usually the directory you will c heck out if you wa nt to w ork on the p roject.
Remember t o specify the trunk when checking o ut; otherwise, you’ll g et the
trunk, all the tags, and a ll the b ranches! This could be quite a lot o f stuff and
usually isn’t what you w ant .

The tags directory is u sed to store named snapshots of t he project. F o r
e x a m p l e , when creating a p roduction r elease, the team will tag the code that
goes into the release. In t he future this can help you re-create the code t hat
was shipped s o that t he team c an find b u g s and fix p roblems.
The branches directory is u sed when you w ant to p ursue different l ines of
development. A good e x a m p l e w ou l d be creating a branch for a production
release. Development on the b ranch can focus on producing a stable r elease,
while the trunk can continue to b e used to develop ne w features.
Although you can store multiple projects within a s ingle Subversion
repository , some people use a different repository for each project. T his
allows some increased flexibility, for e x a m p l e having different sets of users
or a different backup schedule b etween projects, b u t at t he cost of e x t r a
administration over h e a d because each repository needs t o be c onfigured a nd
backed u p individually. If you are using a r epository-per-project style for
managing y our Subversion p rojects, the trunk, tags, and branches
directories will be at t he root of each p roject’s repository.
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>
CREATINGANEMPTYPROJECT 25
Create a base directory f o r the project.
If you are sharing a single repository between multiple projects, create a
directory within the repository for your n ew project.
prompt> svn mkdir -m "Make base directory" \
/>Create a repository f o r the project.
If you are using a s eparate repository f or each project, follow the steps in
T a s k 34, Creating a R epository, on page 106 to create a repository for your
project.
Create trunk, tags, and branches d irectories.
prompt> svn mkdir -m "Initial setup" \

/>prompt> svn mkdir -m "Initial setup" \
/>prompt> svn mkdir -m "Initial setup" \
/>Use T o r t o i s e to create directories.
Right-click i nside any Explorer window , and choose T o r t o i s e S V N >
Repo-browser . Enter the URL for your repository, for e x a m p l e http://svn.
mycompany.com/. T o r t o i s e will show you a repository browser where you
can manipulate your repository. Right-click, a nd choose “ Create folder” as
necessary to create all the directories you need for your project.
Use Cornerstone to create a project.
Select your repository from the repository source list. Cornerstone will show
its r epository browser i n the main window . Ctrl+click t he main window , and
choose “New folder i n MyRepo ” Enter a name for the project, and select
the box to create t op-level directories for t he project. Enter a log message
describing your change, and then click Continue t o create your project.
Related T a s k s
• T a s k 34, Creating a R epository, on page 106
• T a s k 36, Using Third-Party Subversion Hosting, on page 110
Report erratum
this copy is (P1.0 printing, October 2010)
Download from Wow! eBook <www.wowebook.com>

×