Version Control With Subversion
Version Control With Subversion
Ben Collins-Sussman
Brian W. Fitzpatrick
C. Michael Pilato
Draft Draft
Table of Contents
Foreword .....................................................................................................................................................xii
Preface ....................................................................................................................................................... xiv
What Is Subversion? ............................................................................................................................. xiv
Is Subversion the Right Tool? ......................................................................................................... xiv
Subversion's History ...................................................................................................................... xv
Subversion's Architecture ............................................................................................................... xv
Subversion's Components ............................................................................................................. xvii
What's New in Subversion ............................................................................................................ xvii
Audience .......................................................................................................................................... xviii
How to Read This Book ...................................................................................................................... xviii
Conventions Used in This Book .............................................................................................................. xix
Organization of This Book ...................................................................................................................... xx
This Book Is Free ................................................................................................................................. xxi
Acknowledgments ................................................................................................................................ xxi
From Ben Collins-Sussman ........................................................................................................... xxii
From Brian W. Fitzpatrick ............................................................................................................ xxii
From C. Michael Pilato ................................................................................................................ xxii
1. Fundamental Concepts ................................................................................................................................. 1
Version Control Basics ............................................................................................................................ 1
The Repository .............................................................................................................................. 1
The Working Copy ......................................................................................................................... 2
Versioning Models ......................................................................................................................... 2
Version Control the Subversion Way ......................................................................................................... 7
Subversion Repositories .................................................................................................................. 7
Revisions ...................................................................................................................................... 7
Addressing the Repository ............................................................................................................... 8
Subversion Working Copies ............................................................................................................ 10
Summary ............................................................................................................................................. 14
2. Basic Usage .............................................................................................................................................. 15
Help! .................................................................................................................................................. 15
Getting Data into Your Repository ........................................................................................................... 16
Importing Files and Directories ........................................................................................................ 16
Recommended Repository Layout .................................................................................................... 17
What's In a Name? ........................................................................................................................ 17
Creating a Working Copy ....................................................................................................................... 18
Basic Work Cycle ................................................................................................................................. 19
Update Your Working Copy ............................................................................................................ 20
Make Your Changes ...................................................................................................................... 20
Review Your Changes ................................................................................................................... 21
Fix Your Mistakes ......................................................................................................................... 24
Resolve Any Conflicts ................................................................................................................... 25
Commit Your Changes ................................................................................................................... 31
Examining History ................................................................................................................................ 32
Generating a List of Historical Changes ............................................................................................. 32
Examining the Details of Historical Changes ...................................................................................... 34
Browsing the Repository ................................................................................................................ 35
Fetching Older Repository Snapshots ................................................................................................ 36
Sometimes You Just Need to Clean Up ..................................................................................................... 37
Disposing of a Working Copy ......................................................................................................... 37
Recovering from an Interruption ...................................................................................................... 37
Dealing with Structural Conflicts ............................................................................................................. 38
An example Tree Conflict ............................................................................................................... 38
Summary ............................................................................................................................................. 42
iv
Draft Version Control with Subversion [DRAFT] Draft
v
Draft Version Control with Subversion [DRAFT] Draft
vi
Draft Version Control with Subversion [DRAFT] Draft
vii
Draft Version Control with Subversion [DRAFT] Draft
viii
Draft Draft
List of Figures
1. Subversion's architecture ............................................................................................................................. xv
1.1. A typical client/server system ..................................................................................................................... 1
1.2. The problem to avoid ................................................................................................................................ 2
1.3. The lock-modify-unlock solution ................................................................................................................. 3
1.4. The copy-modify-merge solution ................................................................................................................. 5
1.5. The copy-modify-merge solution (continued) ................................................................................................ 5
1.6. The repository ......................................................................................................................................... 7
1.7. The repository's filesystem ........................................................................................................................ 11
4.1. Branches of development .......................................................................................................................... 86
4.2. Starting repository layout .......................................................................................................................... 87
4.3. Repository with new copy ......................................................................................................................... 88
4.4. The branching of one file's history .............................................................................................................. 90
8.1. Files and directories in two dimensions ...................................................................................................... 202
8.2. Versioning time—the third dimension! ...................................................................................................... 203
ix
Draft Draft
List of Tables
1.1. Repository access URLs ............................................................................................................................ 8
2.1. Common log requests ............................................................................................................................... 33
4.1. Branching and merging commands ........................................................................................................... 119
5.1. Repository data store comparison ............................................................................................................. 124
6.1. Comparison of subversion server options ................................................................................................... 153
C.1. Common WebDAV clients ..................................................................................................................... 369
x
Draft Draft
List of Examples
5.1. [Link] (reporting outstanding transactions) ........................................................................................... 134
5.2. Mirror repository's pre-revprop-change hook script ...................................................................................... 145
5.3. Mirror repository's start-commit hook script ............................................................................................... 145
6.1. A sample configuration for anonymous access ............................................................................................ 172
6.2. A sample configuration for authenticated access .......................................................................................... 173
6.3. A sample configuration for mixed authenticated/anonymous access ................................................................ 173
6.4. Disabling path checks altogether .............................................................................................................. 174
7.1. Sample registration entries (.reg) file ......................................................................................................... 188
7.2. [Link] .......................................................................................................................................... 197
7.3. [Link] ......................................................................................................................................... 197
7.4. [Link] ......................................................................................................................................... 198
7.5. [Link] ........................................................................................................................................ 198
8.1. Using the Repository Layer ..................................................................................................................... 209
8.2. Using the Repository layer with Python ..................................................................................................... 211
8.3. A Python status crawler .......................................................................................................................... 212
xi
Draft Draft
Foreword
Karl Fogel
Chicago, March 14, 2004.
A bad Frequently Asked Questions (FAQ) sheet is one that is composed not of the questions people actually ask, but of the ques-
tions the FAQ's author wishes people would ask. Perhaps you've seen the type before:
A: Many of our customers want to know how they can maximize productivity through our patented office group-
ware innovations. The answer is simple. First, click on the File menu, scroll down to In-
crease Productivity, then…
The problem with such FAQs is that they are not, in a literal sense, FAQs at all. No one ever called the tech support line and asked,
“How can we maximize productivity?” Rather, people asked highly specific questions, such as “How can we change the calendar-
ing system to send reminders two days in advance instead of one?” and so on. But it's a lot easier to make up imaginary Frequently
Asked Questions than it is to discover the real ones. Compiling a true FAQ sheet requires a sustained, organized effort: over the
lifetime of the software, incoming questions must be tracked, responses monitored, and all gathered into a coherent, searchable
whole that reflects the collective experience of users in the wild. It calls for the patient, observant attitude of a field naturalist. No
grand hypothesizing, no visionary pronouncements here—open eyes and accurate note-taking are what's needed most.
What I love about this book is that it grew out of just such a process, and shows it on every page. It is the direct result of the au-
thors' encounters with users. It began with Ben Collins-Sussman's observation that people were asking the same basic questions
over and over on the Subversion mailing lists: what are the standard workflows to use with Subversion? Do branches and tags work
the same way as in other version control systems? How can I find out who made a particular change?
Frustrated at seeing the same questions day after day, Ben worked intensely over a month in the summer of 2002 to write The Sub-
version Handbook, a 60-page manual that covered all the basics of using Subversion. The manual made no pretense of being com-
plete, but it was distributed with Subversion and got users over that initial hump in the learning curve. When O'Reilly decided to
publish a full-length Subversion book, the path of least resistance was obvious: just expand the Subversion handbook.
The three coauthors of the new book were thus presented with an unusual opportunity. Officially, their task was to write a book
top-down, starting from a table of contents and an initial draft. But they also had access to a steady stream—indeed, an uncontrol-
lable geyser—of bottom-up source material. Subversion was already in the hands of thousands of early adopters, and those users
were giving tons of feedback, not only about Subversion, but also about its existing documentation.
During the entire time they wrote this book, Ben, Mike, and Brian haunted the Subversion mailing lists and chat rooms incessantly,
carefully noting the problems users were having in real-life situations. Monitoring such feedback was part of their job descriptions
at CollabNet anyway, and it gave them a huge advantage when they set out to document Subversion. The book they produced is
grounded firmly in the bedrock of experience, not in the shifting sands of wishful thinking; it combines the best aspects of user
manual and FAQ sheet. This duality might not be noticeable on a first reading. Taken in order, front to back, the book is simply a
straightforward description of a piece of software. There's the overview, the obligatory guided tour, the chapter on administrative
configuration, some advanced topics, and of course, a command reference and troubleshooting guide. Only when you come back to
it later, seeking the solution to some specific problem, does its authenticity shine out: the telling details that can only result from
encounters with the unexpected, the examples honed from genuine use cases, and most of all the sensitivity to the user's needs and
the user's point of view.
Of course, no one can promise that this book will answer every question you have about Subversion. Sometimes the precision with
which it anticipates your questions will seem eerily telepathic; yet occasionally, you will stumble into a hole in the community's
knowledge and come away empty-handed. When this happens, the best thing you can do is email
<users@[Link]> and present your problem. The authors are still there and still watching, and the authors
include not just the three listed on the cover, but many others who contributed corrections and original material. From the com-
munity's point of view, solving your problem is merely a pleasant side effect of a much larger project—namely, slowly adjusting
this book, and ultimately Subversion itself, to more closely match the way people actually use it. They are eager to hear from you,
not only because they can help you, but because you can help them. With Subversion, as with all active free software projects, you
xii
Draft Foreword Draft
xiii
Draft Draft
Preface
“It is important not to let the perfect become the enemy of the good, even when you can agree on what perfect is.
Doubly so when you can't. As unpleasant as it is to be trapped by past mistakes, you can't make any progress by
being afraid of your own shadow during design.”
—Greg Hudson, Subversion developer
In the world of open source software, the Concurrent Versions System (CVS) was the tool of choice for version control for many
years. And rightly so. CVS was open source software itself, and its nonrestrictive modus operandi and support for networked oper-
ation allowed dozens of geographically dispersed programmers to share their work. It fit the collaborative nature of the open source
world very well. CVS and its semi-chaotic development model have since become cornerstones of open source culture.
But CVS was not without its flaws, and simply fixing those flaws promised to be an enormous effort. Enter Subversion. Subversion
was designed to be a successor to CVS, and its originators set out to win the hearts of CVS users in two ways—by creating an open
source system with a design (and “look and feel”) similar to CVS, and by attempting to avoid most of CVS's noticeable flaws.
While the result wasn't—and isn't—the next great evolution in version control design, Subversion is very powerful, very usable,
and very flexible.
This book is written to document the 1.6 series of the Apache Subversion™ 1 version control system. We have made every attempt
to be thorough in our coverage. However, Subversion has a thriving and energetic development community, so already a number of
features and improvements are planned for future versions that may change some of the commands and specific notes in this book.
What Is Subversion?
Subversion is a free/open source version control system (VCS). That is, Subversion manages files and directories, and the changes
made to them, over time. This allows you to recover older versions of your data or examine the history of how your data changed.
In this regard, many people think of a version control system as a sort of “time machine.”
Subversion can operate across networks, which allows it to be used by people on different computers. At some level, the ability for
various people to modify and manage the same set of data from their respective locations fosters collaboration. Progress can occur
more quickly without a single conduit through which all modifications must occur. And because the work is versioned, you need
not fear that quality is the trade-off for losing that conduit—if some incorrect change is made to the data, just undo that change.
Some version control systems are also software configuration management (SCM) systems. These systems are specifically tailored
to manage trees of source code and have many features that are specific to software development—such as natively understanding
programming languages, or supplying tools for building software. Subversion, however, is not one of these systems. It is a general
system that can be used to manage any collection of files. For you, those files might be source code—for others, anything from
grocery shopping lists to digital video mixdowns and beyond.
If you need to archive old versions of files and directories, possibly resurrect them, or examine logs of how they've changed over
time, then Subversion is exactly the right tool for you. If you need to collaborate with people on documents (usually over a net-
work) and keep track of who made which changes, then Subversion is also appropriate. This is why Subversion is so often used in
software development environments—working on a development team is an inherently social activity, and Subversion makes it
easy to collaborate with other programmers. Of course, there's a cost to using Subversion as well: administrative overhead. You'll
need to manage a data repository to store the information and all its history, and be diligent about backing it up. When working
1
We'll refer to it simply as “Subversion” throughout this book. You'll thank us when you realize just how much space that saves!
xiv
Draft Preface Draft
with the data on a daily basis, you won't be able to copy, move, rename, or delete files the way you usually do. Instead, you'll have
to do all of those things through Subversion.
Assuming you're fine with the extra workflow, you should still make sure you're not using Subversion to solve a problem that other
tools solve better. For example, because Subversion replicates data to all the collaborators involved, a common misuse is to treat it
as a generic distribution system. People will sometimes use Subversion to distribute huge collections of photos, digital music, or
software packages. The problem is that this sort of data usually isn't changing at all. The collection itself grows over time, but the
individual files within the collection aren't being changed. In this case, using Subversion is “overkill.” 2 There are simpler tools that
efficiently replicate data without the overhead of tracking changes, such as rsync or unison.
Subversion's History
In early 2000, CollabNet, Inc. ([Link] began seeking developers to write a replacement for CVS. CollabNet offers
a collaboration software suite called CollabNet Enterprise Edition (CEE), of which one component is version control. Although
CEE 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 con-
trol system from scratch, retaining the basic ideas of CVS, but without the bugs and misfeatures.
In February 2000, they contacted Karl Fogel, the author of Open Source Development with CVS (Coriolis, 1999), and asked if he'd
like to work on this new project. Coincidentally, at the time Karl was already discussing a design for a new version control system
with his friend Jim Blandy. In 1995, the two had started Cyclic Software, a company providing CVS support contracts, and al-
though they later sold the business, they still used CVS every day at their jobs. Their frustration with CVS had led Jim to think
carefully about better ways to manage versioned data, and he'd already come up with not only the Subversion name, but also the
basic design of the Subversion data store. When CollabNet called, Karl immediately agreed to work on the project, and Jim got his
employer, Red Hat Software, to essentially donate him to the project for an indefinite period of time. CollabNet hired Karl and Ben
Collins-Sussman, and detailed design work began in May 2000. With the help of some well-placed prods from Brian Behlendorf
and Jason Robbins of CollabNet, and from Greg Stein (at the time an independent developer active in the WebDAV/DeltaV spe-
cification process), Subversion quickly attracted a community of active developers. It turned out that many people had encountered
the same frustrating experiences with CVS and welcomed the chance to finally do something about it.
The original design team settled on some simple goals. They didn't want to break new ground in version control methodology, they
just wanted to fix CVS. They decided that Subversion would match CVS's features and preserve the same development model, but
not duplicate CVS's most obvious flaws. And although it did not need to be a drop-in replacement for CVS, it should be similar
enough that any CVS user could make the switch with little effort.
After 14 months of coding, Subversion became “self-hosting” on August 31, 2001. That is, Subversion developers stopped using
CVS to manage Subversion's own source code and started using Subversion instead.
While CollabNet started the project, and still funds a large chunk of the work (it pays the salaries of a few full-time Subversion de-
velopers), Subversion is run like most open source projects, governed by a loose, transparent set of rules that encourage merito-
cracy. In 2009, CollabNet worked with the Subversion developers towards the goal of integrating the Subversion project into the
Apache Software Foundation (ASF), one of the most well-known collectives of open source projects in the world. Subversion's
technical roots, community priorities, and development practices were a perfect fit for the ASF, many of whose members were
already active Subversion contributors. In early 2010, Subversion was fully adopted into the ASF's family of top-level projects,
moved its project web presence to [Link] and was rechristened “Apache Subversion”.
Subversion's Architecture
Figure 1, “Subversion's architecture” illustrates a “mile-high” view of Subversion's design.
2
Or as a friend puts it, “swatting a fly with a Buick.”
xv
Draft Preface Draft
On one end is a Subversion repository that holds all of your versioned data. On the other end is your Subversion client program,
which manages local reflections of portions of that versioned data. Between these extremes are multiple routes through a Reposit-
ory Access (RA) layer, some of which go across computer networks and through network servers which then access the repository,
xvi
Draft Preface Draft
others of which bypass the network altogether and access the repository directly.
Subversion's Components
Subversion, once installed, has a number of different pieces. The following is a quick overview of what you get. Don't be alarmed
if the brief descriptions leave you scratching your head—plenty more pages in this book are devoted to alleviating that confusion.
svn
The command-line client program
svnversion
A program for reporting the state (in terms of revisions of the items present) of a working copy
svnlook
A tool for directly inspecting a Subversion repository
svnadmin
A tool for creating, tweaking, or repairing a Subversion repository
mod_dav_svn
A plug-in module for the Apache HTTP Server, used to make your repository available to others over a network
svnserve
A custom standalone server program, runnable as a daemon process or invokable by SSH; another way to make your reposit-
ory available to others over a network.
svndumpfilter
A program for filtering Subversion repository dump streams
svnsync
A program for incrementally mirroring one repository to another over a network
Apache server. The Apache server, however, gained some new logging features of its own, and Subversion's API bindings to
other languages also made great leaps forward.
Audience
This book is written for computer-literate folk who want to use Subversion to manage their data. While Subversion runs on a num-
ber of different operating systems, its primary user interface is command-line-based. That command-line tool (svn), and some ad-
ditional auxiliary programs, are the focus of this book.
For consistency, the examples in this book assume that the reader is using a Unix-like operating system and is relatively comfort-
able with Unix and command-line interfaces. That said, the svn program also runs on non-Unix platforms such as Microsoft Win-
dows. With a few minor exceptions, such as the use of backward slashes (\) instead of forward slashes (/) for path separators, the
input to and output from this tool when run on Windows are identical to that of its Unix counterpart.
Most readers are probably programmers or system administrators who need to track changes to source code. This is the most com-
mon use for Subversion, and therefore it is the scenario underlying all of the book's examples. But Subversion can be used to man-
age changes to any sort of information—images, music, databases, documentation, and so on. To Subversion, all data is just data.
While this book is written with the assumption that the reader has never used a version control system, we've also tried to make it
easy for users of CVS (and other systems) to make a painless leap into Subversion. Special sidebars may mention other version
control systems from time to time, and Appendix B, Subversion for CVS Users summarizes many of the differences between CVS
and Subversion.
Note also that the source code examples used throughout the book are only examples. While they will compile with the proper
compiler incantations, they are intended to illustrate a particular scenario and not necessarily to serve as examples of good pro-
gramming style or practices.
xviii
Draft Preface Draft
Regardless of your learning style, this book aims to be useful to people of widely different backgrounds—from those with no pre-
vious experience in version control to experienced system administrators. Depending on your own background, certain chapters
may be more or less important to you. The following can be considered a “recommended reading list” for various types of readers:
New users
Your administrator has probably set up Subversion already, and you need to learn how to use the client. If you've never used a
version control system, then Chapter 1, Fundamental Concepts is a vital introduction to the ideas behind version control.
Chapter 2, Basic Usage is a guided tour of the Subversion client.
Advanced users
Whether you're a user or administrator, eventually your project will grow larger. You're going to want to learn how to do more
advanced things with Subversion, such as how to use Subversion's property support (Chapter 3, Advanced Topics), how to use
branches and perform merges (Chapter 4, Branching and Merging), how to configure runtime options (Chapter 7, Customizing
Your Subversion Experience), and other things. These chapters aren't critical at first, but be sure to read them once you're com-
fortable with the basics.
Developers
Presumably, you're already familiar with Subversion, and now want to either extend it or build new software on top of its
many APIs. Chapter 8, Embedding Subversion is just for you.
The book ends with reference material—Chapter 9, Subversion Complete Reference is a reference guide for all Subversion com-
mands, and the appendixes cover a number of useful topics. These are the chapters you're mostly likely to come back to after
you've finished the book.
Constant width
Used for literal user input, command output, and command-line options
Italic
Used for program and Subversion tool subcommand names, file and directory names, and new terms
Also, we sprinkled especially helpful or important bits of information throughout the book (in contextually relevant locations), set
off visually so they're easy to find. Look for the following icons as you read:
xix
Draft Preface Draft
This icon designates a warning. Pay close attention to these to avoid running into problems.
Appendix D, Copyright
A copy of the Creative Commons Attribution License, under which this book is licensed.
xx
Draft Preface Draft
• You will always find the latest version of this book in the book's own Subversion repository.
• You can make changes to this book and redistribute it however you wish—it's under a free license. Your only obligation is to
maintain proper attribution to the original authors. Of course, we'd much rather you send feedback and patches to the Subversion
developer community, instead of distributing your private version of this book.
The online home of this book's development and most of the volunteer-driven translation efforts regarding it is ht-
tp://[Link]. There you can find links to the latest releases and tagged versions of the book in various formats, as
well as instructions for accessing the book's Subversion repository (where its DocBook XML source code lives). Feedback is wel-
comed—encouraged, even. Please submit all comments, complaints, and patches against the book sources to
<svnbook-dev@[Link]>.
Acknowledgments
This book would not be possible (nor very useful) if Subversion did not exist. For that, the authors would like to thank Brian
Behlendorf and CollabNet for the vision to fund such a risky and ambitious new open source project; Jim Blandy for the original
Subversion name and design—we love you, Jim; and Karl Fogel for being such a good friend and a great community leader, in that
order. 3
Thanks to O'Reilly and our various editors: Chuck Toporek, Linda Mui, Tatiana Apandi, Mary Brady, and Mary Treseler. Their pa-
tience and support has been tremendous.
Finally, we thank the countless people who contributed to this book with informal reviews, suggestions, and patches. While this is
undoubtedly not a complete list, this book would be incomplete and incorrect without their help: Bhuvaneswaran A, David Alber,
C. Scott Ananian, David Anderson, Ariel Arjona, Seth Arnold, Jani Averbach, Charles Bailey, Ryan Barrett, Francois Beausoleil,
Brian R. Becker, Yves Bergeron, Karl Berry, Jennifer Bevan, Matt Blais, Jim Blandy, Phil Bordelon, Sietse Brouwer, Tom Brown,
Zack Brown, Martin Buchholz, Paul Burba, Sean Callan-Hinsvark, Branko Cibej, Archie Cobbs, Jason Cohen, Ryan Cresawn,
John R. Daily, Peter Davis, Olivier Davy, Robert P. J. Day, Mo DeJong, Brian Denny, Joe Drew, Markus Dreyer, Nick Duffek,
Boris Dusek, Ben Elliston, Justin Erenkrantz, Jens M. Felderhoff, Kyle Ferrio, Shlomi Fish, Julian Foad, Chris Foote, Martin Fur-
ter, Vlad Georgescu, Peter Gervai, Dave Gilbert, Eric Gillespie, David Glasser, Marcel Gosselin, Lieven Govaerts, Steve Green-
land, Matthew Gregan, Tom Gregory, Maverick Grey, Art Haas, Mark E. Hamilton, Eric Hanchrow, Liam Healy, Malte Helmert,
Michael Henderson, Øyvind A. Holm, Greg Hudson, Alexis Huxley, Auke Jilderda, Toby Johnson, Jens B. Jorgensen, Tez Kami-
hira, David Kimdon, Mark Benedetto King, Robert Kleemann, Erik Kline, Josh Knowles, Andreas J. Koenig, Axel Kollmorgen,
Nuutti Kotivuori, Kalin Kozhuharov, Matt Kraai, Regis Kuckaertz, Stefan Kueng, Steve Kunkee, Scott Lamb, Wesley J. Landaker,
Benjamin Landsteiner, Vincent Lefevre, Morten Ludvigsen, Dennis Lundberg, Paul Lussier, Bruce A. Mah, Jonathon Mah, Karl
Heinz Marbaise, Philip Martin, Feliciano Matias, Neil Mayhew, Patrick Mayweg, Gareth McCaughan, Craig McElroy, Simon
McKenna, Christophe Meresse, Jonathan Metillon, Jean-Francois Michaud, Jon Middleton, Robert Moerland, Marcel Molina Jr.,
Tim Moloney, Alexander Mueller, Tabish Mustufa, Christopher Ness, Roman Neuhauser, Mats Nilsson, Greg Noel, Joe Orton,
Eric Paire, Dimitri Papadopoulos-Orfanos, Jerry Peek, Chris Pepper, Amy Lyn Pilato, Kevin Pilch-Bisson, Hans Polak, Dmitriy
Popkov, Michael Price, Mark Proctor, Steffen Prohaska, Daniel Rall, Srinivasa Ramanujan, Jack Repenning, Tobias Ringstrom,
Jason Robbins, Garrett Rooney, Joel Rosdahl, Christian Sauer, Ryan Schmidt, Jochem Schulenklopper, Jens Seidel, Daniel Shahaf,
Larry Shatzer, Danil Shopyrin, Erik Sjoelund, Joey Smith, W. Snyder, Stefan Sperling, Robert Spier, M. S. Sriram, Russell
Steicke, David Steinbrunner, Sander Striker, David Summers, Johan Sundstroem, Ed Swierk, John Szakmeister, Arfrever Frehtes
Taifersar Arahesis, Robert Tasarz, Michael W. Thelen, Mason Thomas, Erik van der Kolk, Joshua Varner, Eric Wadsworth, Chris
Wagner, Colin Watson, Alex Waugh, Chad Whitacre, Andy Whitcroft, Josef Wolf, Luke Worth, Hyrum Wright, Blair Zajac, Flori-
an Zumbiehl, and the entire Subversion community.
3
Oh, and thanks, Karl, for being too overworked to write this book yourself.
xxi
Draft Preface Draft
Thanks to my extended family and friends for their sincere encouragement, despite having no actual interest in the subject. (You
know, the ones who say, “Ooh, you wrote a book?” and then when you tell them it's a computer book, sort of glaze over.)
Thanks to all my close friends, who make me a rich, rich man. Don't look at me that way—you know who you are.
Thanks to my parents for the perfect low-level formatting and being unbelievable role models. Thanks to my kids for the opportun-
ity to pass that on.
To Mike and Ben: it was a pleasure working with you on the book. Heck, it's a pleasure working with you at work!
To everyone in the Subversion community and the Apache Software Foundation, thanks for having me. Not a day goes by where I
don't learn something from at least one of you.
Lastly, thanks to my grandfather, who always told me that “freedom equals responsibility.” I couldn't agree more.
Mom and Dad, thanks for your constant support and enthusiasm. Mom- and Dad-in-law, thanks for all of the same plus your fab-
ulous daughter.
Hats off to Shep Kendall, through whom the world of computers was first opened to me; Ben Collins-Sussman, my tour guide
through the open source world; Karl Fogel, you are my .emacs; Greg Stein, for oozing practical programming know-how; and
Brian Fitzpatrick, for sharing this writing experience with me. To the many folks from whom I am constantly picking up new
knowledge—keep dropping it!
xxii
Draft Draft
Even though the examples in this chapter show people sharing collections of program source code, keep in mind that Subversion
can manage any sort of file collection—it's not limited to helping computer programmers.
In this section, we'll introduce some fairly high-level version control system components and concepts. We'll limit our discussion
to modern version control systems—in today's interconnected world, there is very little point in acknowledging version control sys-
tems which cannot operate across wide-area networks.
The Repository
At the core of the version control system is a repository, which is the central store of that system's data. The repository usually
stores information in the form of a filesystem tree—a hierarchy of files and directories. Any number of clients connect to the repos-
itory, and then read or write to these files. By writing data, a client makes the information available to others; by reading data, the
client receives information from others. Figure 1.1, “A typical client/server system” illustrates this.
Why is this interesting? So far, this sounds like the definition of a typical file server. And indeed, the repository is a kind of file
server, but it's not your usual breed. What makes the repository special is that as the files in the repository are changed, the reposit-
ory remembers each version of those files.
When a client reads data from the repository, it normally sees only the latest version of the filesystem tree. But what makes a ver-
sion control client interesting is that it also has the ability to request previous states of the filesystem from the repository. A version
control client can ask historical questions such as “What did this directory contain last Wednesday?” and “Who was the last person
to change this file, and what changes did he make?” These are the sorts of questions that are at the heart of any version control sys-
1
Draft Fundamental Concepts Draft
tem.
A working copy is, quite literally, a local copy of a particular version of a user's VCS-managed data upon which that user is free to
work. Working copies 1 appear to other software just as any other local directory full of files, so those programs don't have to be
“version-control-aware” in order to read from and write to that data. The task of managing the working copy and communicating
changes made to its contents to and from the repository falls squarely to the version control system's client software.
Versioning Models
If the primary mission of a version control system is to track the various versions of digital information over time, a very close sec-
ondary mission in any modern version control system is to enable collaborative editing and sharing of that data. But different sys-
tems use different strategies to achieve this. It's important to understand these different strategies, for a couple of reasons. First, it
will help you compare and contrast existing version control systems, in case you encounter other systems similar to Subversion.
Beyond that, it will also help you make more effective use of Subversion, since Subversion itself supports a couple of different
ways of working.
Consider the scenario shown in Figure 1.2, “The problem to avoid”. Suppose we have two coworkers, Harry and Sally. They each
decide to edit the same repository file at the same time. If Harry saves his changes to the repository first, it's possible that (a few
moments later) Sally could accidentally overwrite them with her own new version of the file. While Harry's version of the file
won't be lost forever (because the system remembers every change), any changes Harry made won't be present in Sally's newer ver-
sion of the file, because she never saw Harry's changes to begin with. Harry's work is still effectively lost—or at least missing from
the latest version of the file—and probably by accident. This is definitely a situation we want to avoid!
1
The term “working copy” can be generally applied to any one file version's local instance. When most folks use the term, though, they are referring to a whole dir-
ectory tree containing files and subdirectories managed by the version control system.
2
Draft Fundamental Concepts Draft
3
Draft Fundamental Concepts Draft
The problem with the lock-modify-unlock model is that it's a bit restrictive and often becomes a roadblock for users:
• Locking may cause administrative problems. Sometimes Harry will lock a file and then forget about it. Meanwhile, because
Sally is still waiting to edit the file, her hands are tied. And then Harry goes on vacation. Now Sally has to get an administrator
to release Harry's lock. The situation ends up causing a lot of unnecessary delay and wasted time.
• Locking may cause unnecessary serialization. What if Harry is editing the beginning of a text file, and Sally simply wants to edit
the end of the same file? These changes don't overlap at all. They could easily edit the file simultaneously, and no great harm
would come, assuming the changes were properly merged together. There's no need for them to take turns in this situation.
• Locking may create a false sense of security. Suppose Harry locks and edits file A, while Sally simultaneously locks and edits
file B. But what if A and B depend on one another, and the changes made to each are semantically incompatible? Suddenly A
and B don't work together anymore. The locking system was powerless to prevent the problem—yet it somehow provided a false
sense of security. It's easy for Harry and Sally to imagine that by locking files, each is beginning a safe, insulated task, and thus
they need not bother discussing their incompatible changes early on. Locking often becomes a substitute for real communication.
4
Draft Fundamental Concepts Draft
independently, modifying their private copies. Finally, the private copies are merged together into a new, final version. The version
control system often assists with the merging, but ultimately, a human being is responsible for making it happen correctly.
Here's an example. Say that Harry and Sally each create working copies of the same project, copied from the repository. They work
concurrently and make changes to the same file A within their copies. Sally saves her changes to the repository first. When Harry
attempts to save his changes later, the repository informs him that his file A is out of date. In other words, file A in the repository
has somehow changed since he last copied it. So Harry asks his client to merge any new changes from the repository into his work-
ing copy of file A. Chances are that Sally's changes don't overlap with his own; once he has both sets of changes integrated, he
saves his working copy back to the repository. Figure 1.4, “The copy-modify-merge solution” and Figure 1.5, “The copy-modi-
fy-merge solution (continued)” show this process.
5
Draft Fundamental Concepts Draft
But what if Sally's changes do overlap with Harry's changes? What then? This situation is called a conflict, and it's usually not
much of a problem. When Harry asks his client to merge the latest repository changes into his working copy, his copy of file A is
somehow flagged as being in a state of conflict: he'll be able to see both sets of conflicting changes and manually choose between
them. Note that software can't automatically resolve conflicts; only humans are capable of understanding and making the necessary
intelligent choices. Once Harry has manually resolved the overlapping changes—perhaps after a discussion with Sally—he can
safely save the merged file back to the repository.
The copy-modify-merge model may sound a bit chaotic, but in practice, it runs extremely smoothly. Users can work in parallel,
never waiting for one another. When they work on the same files, it turns out that most of their concurrent changes don't overlap at
all; conflicts are infrequent. And the amount of time it takes to resolve conflicts is usually far less than the time lost by a locking
system.
In the end, it all comes down to one critical factor: user communication. When users communicate poorly, both syntactic and se-
mantic conflicts increase. No system can force users to communicate perfectly, and no system can detect semantic conflicts. So
there's no point in being lulled into a false sense of security that a locking system will somehow prevent conflicts; in practice, lock-
ing seems to inhibit productivity more than anything else.
While the lock-modify-unlock model is considered generally harmful to collaboration, sometimes locking is appropriate.
The copy-modify-merge model is based on the assumption that files are contextually mergeable—that is, that the majority of
the files in the repository are line-based text files (such as program source code). But for files with binary formats, such as
6
Draft Fundamental Concepts Draft
artwork or sound, it's often impossible to merge conflicting changes. In these situations, it really is necessary for users to take
strict turns when changing the file. Without serialized access, somebody ends up wasting time on changes that are ultimately
discarded.
While Subversion is primarily a copy-modify-merge system, it still recognizes the need to lock an occasional file, and thus
provides mechanisms for this. We discuss this feature in the section called “Locking”.
Subversion Repositories
Subversion implements the concept of a version control repository much as any other modern version control system would. Un-
like a working copy, a Subversion repository is an abstract entity, able to be operated upon almost exclusively by Subversion's own
libraries and tools. As most of a user's Subversion interactions involve the use of the Subversion client and occur in the context of a
working copy, we spend the majority of this book discussing the Subversion working copy and how to manipulate it. For the finer
details of the repository, though, check out Chapter 5, Repository Administration.
Revisions
A Subversion client commits (that is, communicates the changes made to) any number of files and directories as a single atomic
transaction. By atomic transaction, we mean simply this: either all of the changes are accepted into the repository, or none of them
is. Subversion tries to retain this atomicity in the face of program crashes, system crashes, network problems, and other users' ac-
tions.
Each time the repository accepts a commit, this creates a new state of the filesystem tree, called a revision. Each revision is as-
signed a unique natural number, one greater than the number assigned to the previous revision. The initial revision of a freshly cre-
ated repository is numbered 0 and consists of nothing but an empty root directory.
Figure 1.6, “The repository” illustrates a nice way to visualize the repository. Imagine an array of revision numbers, starting at 0,
stretching from left to right. Each revision number has a filesystem tree hanging below it, and each tree is a “snapshot” of the way
the repository looked after a commit.
7
Draft Fundamental Concepts Draft
Unlike most version control systems, Subversion's revision numbers apply to entire trees, not individual files. Each revision
number selects an entire tree, a particular state of the repository after some committed change. Another way to think about it
is that revision N represents the state of the repository filesystem after the Nth commit. When Subversion users talk about
“revision 5 of foo.c,” they really mean “foo.c as it appears in revision 5.” Notice that in general, revisions N and M of a
file do not necessarily differ! Many other version control systems use per-file revision numbers, so this concept may seem
unusual at first. (Former CVS users might want to see Appendix B, Subversion for CVS Users for more details.)
Subversion repository URLs aren't limited to only the http:// variety. Because Subversion offers several different ways for its
clients to communicate with its servers, the URLs used to address the repository change subtly depending on which repository ac-
cess mechanism is employed. Table 1.1, “Repository access URLs” describes how different URL schemes map to the available re-
pository access methods. For more details about Subversion's server options, see Chapter 6, Server Configuration.
8
Draft Fundamental Concepts Draft
Subversion's handling of URLs has some notable nuances. For example, URLs containing the file:// access method (used for
local repositories) must, in accordance with convention, have either a server name of localhost or no server name at all:
Also, users of the file:// scheme on Windows platforms will need to use an unofficially “standard” syntax for accessing repos-
itories that are on the same machine, but on a different drive than the client's current working drive. Either of the two following
URL path syntaxes will work, where X is the drive on which the repository resides:
In the second syntax, you need to quote the URL so that the vertical bar character is not interpreted as a pipe. Also, note that a URL
uses forward slashes even though the native (non-URL) form of a path on Windows uses backslashes.
You cannot use Subversion's file:// URLs in a regular web browser the way typical file:// URLs can. When
you attempt to view a file:// URL in a regular web browser, it reads and displays the contents of the file at that
location by examining the filesystem directly. However, Subversion's resources exist in a virtual filesystem (see the
section called “Repository Layer”), and your browser will not understand how to interact with that filesystem.
The Subversion client will automatically encode URLs as necessary, just like a web browser does. For example, if a URL contains
a space or upper-ASCII character as in the following:
then Subversion will escape the unsafe characters and behave as though you had typed:
If the URL contains spaces, be sure to place it within quotation marks so that your shell treats the whole thing as a single argument
to the svn program.
In Subversion 1.6, a new caret (^) notation was introduced as a shorthand for “the URL of the repository's root directory”. For ex-
ample:
9
Draft Fundamental Concepts Draft
In this example, we're specifying a URL for the /tags/bigsandwich directory in the root of the repository. Note that this
URL syntax works only when your current working directory is a working copy—the command-line client knows the repository's
root URL by looking at the working copy's metadata.
After you've made some changes to the files in your working copy and verified that they work properly, Subversion provides you
with commands to “publish” your changes to the other people working with you on your project (by writing to the repository). If
other people publish their own changes, Subversion provides you with commands to merge those changes into your working copy
(by reading from the repository).
A working copy also contains some extra files, created and maintained by Subversion, to help it carry out these commands. In par-
ticular, each directory in your working copy contains a subdirectory named .svn, also known as the working copy's administrat-
ive directory. The files in each administrative directory help Subversion recognize which files contain unpublished changes, and
which files are out of date with respect to others' work.
• What revision your working file is based on (this is called the file's working revision)
• A timestamp recording when the local copy was last updated by the repository
Given this information, by talking to the repository, Subversion can tell which of the following four states a working file is in:
10
Draft Fundamental Concepts Draft
A typical Subversion repository often holds the files (or source code) for several projects; usually, each project is a subdirectory in
the repository's filesystem tree. In this arrangement, a user's working copy will usually correspond to a particular subtree of the re-
pository.
For example, suppose you have a repository that contains two software projects, paint and calc. Each project lives in its own
top-level subdirectory, as shown in Figure 1.7, “The repository's filesystem”.
To get a working copy, you must check out some subtree of the repository. (The term check out may sound like it has something to
do with locking or reserving resources, but it doesn't; it simply creates a private copy of the project for you.) For example, if you
check out /calc, you will get a working copy like this:
11
Draft Fundamental Concepts Draft
The list of letter As in the left margin indicates that Subversion is adding a number of items to your working copy. You now have a
personal copy of the repository's /calc directory, with one additional entry—.svn—which holds the extra information needed
by Subversion, as mentioned earlier.
Suppose you make changes to button.c. Since the .svn directory remembers the file's original modification date and contents,
Subversion can tell that you've changed the file. However, Subversion does not make your changes public until you explicitly tell it
to. The act of publishing your changes is more commonly known as committing (or checking in) changes to the repository.
To publish your changes to others, you can use Subversion's svn commit command:
Now your changes to button.c have been committed to the repository, with a note describing your change (namely, that you
fixed a typo). If another user checks out a working copy of /calc, she will see your changes in the latest version of the file.
Suppose you have a collaborator, Sally, who checked out a working copy of /calc at the same time you did. When you commit
your change to button.c, Sally's working copy is left unchanged; Subversion modifies working copies only at the user's request.
To bring her project up to date, Sally can ask Subversion to update her working copy, by using the svn update command. This will
incorporate your changes into her working copy, as well as any others that have been committed since she checked it out.
$ pwd
/home/sally/calc
$ ls -A
Makefile button.c integer.c .svn/
$ svn update
U button.c
Updated to revision 57.
$
The output from the svn update command indicates that Subversion updated the contents of button.c. Note that Sally didn't
need to specify which files to update; Subversion uses the information in the .svn directory as well as further information in the
repository, to decide which files need to be brought up to date.
calc/Makefile:4
integer.c:4
button.c:4
At the moment, this working directory corresponds exactly to revision 4 in the repository. However, suppose you make a change to
button.c, and commit that change. Assuming no other commits have taken place, your commit will create revision 5 of the re-
pository, and your working copy will now look like this:
12
Draft Fundamental Concepts Draft
calc/Makefile:4
integer.c:4
button.c:5
Suppose that, at this point, Sally commits a change to integer.c, creating revision 6. If you use svn update to bring your work-
ing copy up to date, it will look like this:
calc/Makefile:6
integer.c:6
button.c:6
Sally's change to integer.c will appear in your working copy, and your change will still be present in button.c. In this ex-
ample, the text of Makefile is identical in revisions 4, 5, and 6, but Subversion will mark your working copy of Makefile with
revision 6 to indicate that it is still current. So, after you do a clean update at the top of your working copy, it will generally corres-
pond to exactly one revision in the repository.
The main side effect of this rule is that it means a working copy has to do extra bookkeeping to track mixed revisions as well as be
tolerant of the mixture. It's made more complicated by the fact that directories themselves are versioned.
For example, suppose you have a working copy entirely at revision 10. You edit the file [Link] and then perform an svn com-
mit, which creates revision 15 in the repository. After the commit succeeds, many new users would expect the working copy to be
entirely at revision 15, but that's not the case! Any number of changes might have happened in the repository between revisions 10
and 15. The client knows nothing of those changes in the repository, since you haven't yet run svn update, and svn commit doesn't
pull down new changes. If, on the other hand, svn commit were to automatically download the newest changes, it would be pos-
sible to set the entire working copy to revision 15—but then we'd be breaking the fundamental rule of “push” and “pull” remaining
separate actions. Therefore, the only safe thing the Subversion client can do is mark the one file—[Link]—as being at revi-
sion 15. The rest of the working copy remains at revision 10. Only by running svn update can the latest changes be downloaded
and the whole working copy be marked as revision 15.
Often, new users are completely unaware that their working copy contains mixed revisions. This can be confusing, because many
client commands are sensitive to the working revision of the item they're examining. For example, the svn log command is used to
display the history of changes to a file or directory (see the section called “Generating a List of Historical Changes”). When the
user invokes this command on a working copy object, he expects to see the entire history of the object. But if the object's working
revision is quite old (often because svn update hasn't been run in a long time), the history of the older version of the object is
shown.
13
Draft Fundamental Concepts Draft
when a bug first came into existence in a specific file. This is the “time machine” aspect of a version control system—the feature
that allows you to move any portion of your working copy forward and backward in history.
First, you cannot commit the deletion of a file or directory that isn't fully up to date. If a newer version of the item exists in the re-
pository, your attempt to delete will be rejected to prevent you from accidentally destroying changes you've not yet seen.
Second, you cannot commit a metadata change to a directory unless it's fully up to date. You'll learn about attaching “properties” to
items in Chapter 3, Advanced Topics. A directory's working revision defines a specific set of entries and properties, and thus com-
mitting a property change to an out-of-date directory may destroy properties you've not yet seen.
Summary
We covered a number of fundamental Subversion concepts in this chapter:
• We introduced the notions of the central repository, the client working copy, and the array of repository revision trees.
• We saw some simple examples of how two collaborators can use Subversion to publish and receive changes from one another,
using the “copy-modify-merge” model.
• We talked a bit about the way Subversion tracks and manages information in a working copy.
At this point, you should have a good idea of how Subversion works in the most general sense. Armed with this knowledge, you
should now be ready to move into the next chapter, which is a detailed tour of Subversion's commands and features.
14
Draft Draft
Note that this chapter is not meant to be an exhaustive list of all of Subversion's commands—rather, it's a conversational introduc-
tion to the most common Subversion tasks that you'll encounter. This chapter assumes that you've read and understood Chapter 1,
Fundamental Concepts and are familiar with the general model of Subversion. For a complete reference of all commands, see
Chapter 9, Subversion Complete Reference.
Also, this chapter assumes that the reader is seeking information about how to interact in a basic fashion with an existing Subver-
sion repository. No repository means no working copy; no working copy means not much of interest in this chapter. There are
many Internet sites which offer free or inexpensive Subversion repository hosting services. Or, if you'd prefer to set up and admin-
ister your own repositories, check out Chapter 5, Repository Administration. But don't expect the examples in this chapter to work
without the user having access to a Subversion repository.
Finally, any Subversion operation that contacts the repository over a network may potentially require that the user authenticate. For
the sake of simplicity, our examples throughout this chapter avoid demonstrating and discussing authentication. Be aware that if
you hope to apply the knowledge herein to an existing, real-world Subversion instance, you'll probably be forced to provide at least
a username and password to the server. See the section called “Client Credentials” for a detailed description of Subversion's hand-
ling of authentication and client credentials.
Help!
It goes without saying that this book exists to be a source of information and assistance for Subversion users new and old. Conveni-
ently, though, the Subversion command-line is self-documenting, alleviating the need to grab a book off the shelf (wooden, virtual,
or otherwise). The svn help command is your gateway to that built-in documentation:
$ svn help
Subversion command-line client, version 1.6.13.
Type 'svn help <subcommand>' for help on a specific subcommand.
Type 'svn --version' to see the program version and RA modules
or 'svn --version --quiet' to see just the version number.
Most subcommands take file and/or directory arguments, recursing
on the directories. If no arguments are supplied to such a
command, it recurses on the current directory (inclusive) by default.
Available subcommands:
add
blame (praise, annotate, ann)
cat
…
As described in the previous output, you can ask for help on a particular subcommand by running svn help SUBCOMMAND.
Subversion will respond with the full usage message for that subcommand, including its syntax, options, and behavior:
15
Draft Basic Usage Draft
The Subversion command-line client has numerous command modifiers. Some folks refer to such things as “switches” or
“flags”—in this book, we'll call them “options”. You'll find the options supported by a given svn subcommand, plus a set of
options which are globally supported by all subcommands, listed near the bottom of the built-in usage message for that sub-
command.
Subversion's options have two distinct forms: short options are a single hyphen followed by a single letter, and long options
consist of two hyphens followed by several letters and hyphens (e.g., -s and --this-is-a-long-option, respect-
ively). Every option has at least one long format. Some, such as the --changelist option, feature an abbreviated long-
format alias (--cl, in this case). Only certain options—generally the most-used ones—have an additional short format. To
maintain clarity in this book, we usually use the long form in code examples, but when describing options, if there's a short
form, we'll provide the long form (to improve clarity) and the short form (to make it easier to remember). Use the form
you're more comfortable with when executing your own Subversion commands.
Many Unix-based distributions of Subversion include manual pages of the sort that can be invoked using the man program, but
those tend to carry only pointers to other sources of real help, such as the project's website and to the website which hosts this
book. Also, several companies offer Subversion help and support, too, usually via a mixture of web-based discussion forums and
fee-based consulting. And of course, the Internet holds a decade's worth of Subversion-related discussions just begging to be loc-
ated by your favorite search engine. Subversion help is never too far away.
The previous example copied the contents of the local directory mytree into the directory some/project in the repository.
Note that you didn't have to create that new directory first—svn import does that for you. Immediately after the commit, you can
see your data in the repository:
16
Draft Basic Usage Draft
bar.c
foo.c
subdir/
$
Note that after the import is finished, the original local directory is not converted into a working copy. To begin working on that
data in a versioned fashion, you still need to create a fresh working copy of that tree.
To counteract this confusion, we recommend that you follow a repository layout convention (established long ago, in the nascency
of the Subversion project itself) in which a handful of strategically named Subversion repository directories convey valuable mean-
ing about the data they hold. Most projects have a recognizable “main line”, or trunk, of development; some branches, which are
divergent copies of development lines; and some tags, which are named, stable snapshots of a particular line of development. So
we first recommend that each project have a recognizable project root in the repository, a directory under which all of the ver-
sioned information for that project—and only that project—lives. Secondly, we suggest that each project root contain a trunk
subdirectory for the main development line, a branches subdirectory in which specific branches (or collections of branches) will
be created, and a tags subdirectory in which specific tags (or collections of tags) will be created. Of course, if a repository houses
only a single project, the root of the repository can serve as the project root, too.
We talk much more about tags and branches in Chapter 4, Branching and Merging. For details and some advice on how to set up
repositories when you have multiple projects, see the section called “Repository Layout”. Finally, we discuss project roots more in
the section called “Planning Your Repository Organization”.
What's In a Name?
Subversion tries hard not to limit the type of data you can place under version control. The contents of files and property values are
stored and transmitted as binary data, and the section called “File Content Type” tells you how to give Subversion a hint that
“textual” operations don't make sense for a particular file. There are a few places, however, where Subversion places restrictions on
information it stores.
Subversion internally handles certain bits of data—for example, property names, pathnames, and log messages—as UTF-
8-encoded Unicode. This is not to say that all your interactions with Subversion must involve UTF-8, though. As a general rule,
Subversion clients will gracefully and transparently handle conversions between UTF-8 and the encoding system in use on your
computer, if such a conversion can meaningfully be done (which is the case for most common encodings in use today).
17
Draft Basic Usage Draft
In WebDAV exchanges and older versions of some of Subversion's administrative files, paths are used as XML attribute values,
and property names in XML tag names. This means that pathnames can contain only legal XML (1.0) characters, and properties are
further limited to ASCII characters. Subversion also prohibits TAB, CR, and LF characters in path names to prevent paths from be-
ing broken up in diffs or in the output of commands such as svn log or svn status.
While it may seem like a lot to remember, in practice these limitations are rarely a problem. As long as your locale settings are
compatible with UTF-8 and you don't use control characters in path names, you should have no trouble communicating with Sub-
version. The command-line client adds an extra bit of help—to create “legally correct” versions for internal use it will automatic-
ally escape illegal path characters as needed in URLs that you type.
Although the preceding example checks out the trunk directory, you can just as easily check out a deeper subdirectory of a reposit-
ory by specifying that subdirectory's URL as the checkout URL:
Since Subversion uses a copy-modify-merge model instead of lock-modify-unlock (see the section called “Versioning Models”),
you can immediately make changes to the files and directories in your working copy. Your working copy is just like any other col-
lection of files and directories on your system. You can edit the files inside it, rename it, even delete the entire working copy and
forget about it.
While your working copy is “just like any other collection of files and directories on your system,” you can edit files
at will, but you must tell Subversion about everything else that you do. For example, if you want to copy or move an
item in a working copy, you should use svn copy or svn move instead of the copy and move commands provided by
your operating system. We'll talk more about them later in this chapter.
Unless you're ready to commit the addition of a new file or directory or changes to existing ones, there's no need to further notify
the Subversion server that you've done anything.
18
Draft Basic Usage Draft
Every directory in a working copy contains an administrative area—a subdirectory named .svn. Usually, directory listing
commands won't show this subdirectory, but it is nevertheless an important directory. Whatever you do, don't delete or
change anything in the administrative area! Subversion use that directory and its contents to manage your working copy.
If you accidentally remove the .svn subdirectory, the easiest way to fix the problem is to remove the entire containing dir-
ectory (a normal system deletion, not svn delete), then run svn update from a parent directory. The Subversion client
will download the directory you've deleted, with a new .svn area as well.
Notice that in the previous pair of examples, Subversion chose to create a working copy in a directory named for the final compon-
ent of the checkout URL. This occurs only as a convenience to the user when the checkout URL is the only bit of information
provided to the svn checkout command. Subversion's command-line client gives you additional flexibility, though, allowing you
to optionally specify the local directory name that Subversion should use for the working copy it [Link] example:
If the local directory you specify doesn't yet exist, that's okay—svn checkout will create it for you.
1. Update your working copy. This involves the use of the svn update command.
2. Make your changes. The most common changes that you'll make are edits to the contents of your existing files. But sometimes
you need to add, remove, copy and move files and directories—the svn add, svn delete, svn copy, and svn move commands
handle those sorts of structural changes within the working copy.
3. Review your changes. The svn status and svn diff commands are critical to reviewing the changes you've made in your working
copy.
4. Fix your mistakes. Nobody's perfect, so as you review your changes, you may spot something that's not quite right. Sometimes
the easiest way to fix a mistake is start all over again from scratch. The svn revert command restores a file or directory to its
unmodified state.
5. Resolve any conflicts (merge others' changes). In the time it takes you to make and review your changes, others might have
made and published changes, too. You'll want to integrate their changes into your working copy to avoid the potential out-
of-dateness scenarios when you attempt to publish your own. Again, the svn update command is the way to do this. If this res-
ults in local conflicts, you'll need to resolve those using the svn resolve command.
6. Publish (commit) your changes. The svn commit command transmits your changes to the repository where, if they are accepted,
they create the newest versions of all the things you modified. Now others can see your work, too!
19
Draft Basic Usage Draft
Use svn update to bring your working copy into sync with the latest revision in the repository:
$ svn update
U foo.c
U bar.c
Updated to revision 2.
$
In this case, it appears that someone checked in modifications to both foo.c and bar.c since the last time you updated, and Sub-
version has updated your working copy to include those changes.
When the server sends changes to your working copy via svn update, 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. To find out what these letters mean, run svn help
update.
On non-Windows platforms, Subversion is able to version files of the special type symbolic link (or “symlink”). A symlink is
a file that acts as a sort of transparent reference to some other object in the filesystem, allowing programs to read and write to
those objects indirectly by way of performing operations on the symlink itself.
When a symlink is committed into a Subversion repository, Subversion remembers that the file was in fact a symlink, as well
as the object to which the symlink “points.” When that symlink is checked out to another working copy on a non-Windows
system, Subversion reconstructs a real filesystem-level symbolic link from the versioned symlink. But that doesn't in any
way limit the usability of working copies on systems such as Windows that do not support symlinks. On such systems, Sub-
version simply creates a regular text file whose contents are the path to which to the original symlink pointed. While that file
can't be used as a symlink on a Windows system, it also won't prevent Windows users from performing their other Subver-
sion-related activities.
Here is an overview of the five Subversion subcommands that you'll use most often to make tree changes:
20
Draft Basic Usage Draft
Subversion does offer ways to immediately commit tree changes to the repository without an explicit commit action. In par-
ticular, specific uses of svn mkdir, svn copy, svn move, and svn delete can operation directly on repository URLs as well as
on working copy paths. Of course, as previously mentioned, svn import always makes direct changes to the repository.
There are pros and cons to performing URL-based operations. One obvious advantage to doing so is speed: sometimes,
checking out a working copy that you don't already have solely to perform some seemingly simple action is an overbearing
cost. A disadvantage is that you are generally limited to a single, or single type of, operation at a time when operating dir-
ectly on URLs. Finally, the primary advantage of a working copy is in its utility as a sort of “staging area” for changes. You
can make sure that the changes you are about to commit make sense in the larger scope of your project before committing
them. And, of course, these staged changes can be as complex or as a simple as they need to be, yet result in but a single new
revision when committed.
You can use the commands svn status, svn diff, and svn revert without any network access even if your repository is across
the network. This makes it easy to manage and review your changes-in-progress when you are working offline or are other-
wise unable to contact your repository over the network.
Subversion does this by keeping private caches of pristine, unmodified versions of each versioned file inside its working
copy administrative areas. This allows Subversion to report—and revert—local modifications to those files without network
access. This cache (called the text-base) also allows Subversion to send the user's local modifications during a commit to the
1
Of course, nothing is ever totally deleted from the repository—just from its HEAD revision. You may continue to access the deleted item in previous revisions.
Should you desire to resurrect the item so that it is again present in HEAD, see the section called “Resurrecting Deleted Items”.
21
Draft Basic Usage Draft
server as a compressed delta (or “difference”) against the pristine version. Having this cache is a tremendous benefit—even
if you have a fast Internet connection, it's generally much faster to send only a file's changes rather than the whole file to the
server.
Because the cvs status command's output was so noisy, and because cvs update not only performs an update, but
also reports the status of your local changes, most CVS users have grown accustomed to using cvs update to report
their changes. In Subversion, the update and status reporting facilities are completely separate. See the section called
“Distinction Between Status and Update” for more details.
If you run svn status at the top of your working copy with no additional arguments, it will detect and report all file and tree
changes you've made. Here are a few examples of the most common status codes that svn status can return. (Note that the text fol-
lowing # is not actually printed by svn status.)
In this output format, svn status prints six columns of characters, followed by several whitespace characters, followed by a file or
directory name. The first column tells the status of a file or directory and/or its contents. The codes we listed are:
A item
The file, directory, or symbolic link item has been scheduled for addition into the repository.
C item
The file item is in a state of conflict. That is, changes received from the server during an update overlap with local changes
that you have in your working copy (and weren't resolved during the update). You must resolve this conflict before committing
your changes to the repository.
D item
The file, directory, or symbolic link item has been scheduled for deletion from the repository.
M item
The contents of the file item have been modified.
If you pass a specific path to svn status, you get information about that item alone:
svn status also has a --verbose (-v) option, which will show you the status of every item in your working copy, even if it has
not been changed:
$ svn status -v
22
Draft Basic Usage Draft
M 44 23 sally README
44 30 sally INSTALL
M 44 20 harry bar.c
44 18 ira stuff
44 35 harry stuff/trout.c
D 44 19 ira stuff/fish.c
44 21 sally stuff/things
A 0 ? ? stuff/things/bloo.h
44 36 harry stuff/things/gloo.c
This is the “long form” output of svn status. The letters in the first column mean the same as before, but the second column shows
the working revision of the item. The third and fourth columns show the revision in which the item last changed, and who changed
it.
None of the prior invocations to svn status contact the repository—they merely report what is known about the working copy
items based on the records stored in the working copy administrative area and on the timestamps and contents of modified files.
But sometimes it is useful to see which of the items in your working copy have been modified in the repository since the last time
you updated your working copy. For this, svn status offers the --show-updates (-u) option, which contacts the repository and
adds information about items that are out of date:
$ svn status -u -v
M * 44 23 sally README
M 44 20 harry bar.c
* 44 35 harry stuff/trout.c
D 44 19 ira stuff/fish.c
A 0 ? ? stuff/things/bloo.h
Status against revision: 46
Notice in the previous example the two asterisks: if you were to run svn update at this point, you would receive changes to
README and trout.c. This tells you some very useful information—because one of those items is also one that you have locally
modified (the file README), you'll need to update and get the servers changes for that file before you commit, or the repository
will reject your commit for being out of date. We discuss this in more detail later.
svn status can display much more information about the files and directories in your working copy than we've shown here—for an
exhaustive description of svn status and its output, see svn status.
Here's an example:
$ svn diff
Index: bar.c
===================================================================
--- bar.c (revision 3)
+++ bar.c (working copy)
@@ -1,7 +1,12 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
23
Draft Basic Usage Draft
+
+#include <stdio.h>
int main(void) {
- printf("Sixty-four slices of American Cheese...\n");
+ printf("Sixty-five slices of American Cheese...\n");
return 0;
}
Index: README
===================================================================
--- README (revision 3)
+++ README (working copy)
@@ -193,3 +193,4 @@
+Note to self: pick up laundry.
Index: stuff/fish.c
===================================================================
--- stuff/fish.c (revision 1)
+++ stuff/fish.c (working copy)
-Welcome to the file known as 'fish'.
-Information on fish will be here soon.
Index: stuff/things/bloo.h
===================================================================
--- stuff/things/bloo.h (revision 8)
+++ stuff/things/bloo.h (working copy)
+Here is a new file to describe
+things about bloo.
The svn diff command produces this output by comparing your working files against its pristine text-base. Files scheduled for ad-
dition are displayed as files in which every line was added; files scheduled for deletion are displayed as if every line was removed
from those files. The output from svn diff is compatible with the patch program. The patch program reads and applies patch files
(or “patches”), which are files that describe differences made to one or more files. Because of this, you can share the changes
you've made in your working copy with someone else without first committing those changes by creating a patch file from the re-
directed output of svn diff:
Subversion uses its internal diff engine, which produces unified diff format, by default. If you want diff output in a different
format, specify an external diff program using --diff-cmd and pass any additional flags that it needs via the --extensions
(-x) option. For example, you might want Subversion to defer its difference calculation and display to the GNU diff program, ask-
ing that program to print local modifications made to the file foo.c in context diff format (another flavor of difference format)
while ignoring changes made only to the case of the letters used in the file's contents:
24
Draft Basic Usage Draft
patch -R. And there are probably other approaches you could take.
Fortunately in Subversion, undoing your work and starting over from scratch doesn't require such acrobatics. Just use the svn re-
vert command:
In this example, Subversion has reverted the file to its premodified state by overwriting it with the pristine version of the file
cached in the text-base area. But note that svn revert can undo any scheduled operation—for example, you might decide that you
don't want to add a new file after all:
The svn revert command offers salvation for imperfect people. It can save you huge amounts of time and energy that would other-
wise be spent manually unmaking changes or, worse, disposing of your working copy and checking out a fresh one just to have a
clean slate to work with again.
Suppose you run svn update and you see this sort of interesting output:
$ svn update
U INSTALL
G README
Conflict discovered in 'bar.c'.
Select: (p) postpone, (df) diff-full, (e) edit,
25
Draft Basic Usage Draft
The U (which stands for “Updated”) and G (for “merGed”) codes are no cause for concern; those files cleanly absorbed changes
from the repository. A file marked with U contains no local changes but was updated with changes from the repository. One
marked with G had local changes to begin with, but the changes coming from the repository didn't overlap with those local
changes.
It's the next few lines which are interesting. First, Subversion reports to you that in its attempt to merge outstanding server changes
into the file bar.c, it has detected that some of those changes clash with local modifications you've made to that file in your
working copy but have not yet committed. Perhaps someone has changed the same line of text you also changed. Whatever the
reason, Subversion instantly flags this file as being in a state of conflict. It then asks you what you want to do about the problem,
allowing you to interactively choose an action to take toward resolving the conflict. The most commonly used options are dis-
played, but you can see all of the options by typing h:
…
(p) postpone - mark the conflict to be resolved later
(df) diff-full - show all changes made to merged file
(e) edit - change merged file in an editor
(r) resolved - accept merged version of file
(mf) mine-full - accept my version of entire file (ignore their changes)
(tf) theirs-full - accept their version of entire file (lose my changes)
(l) launch - launch external tool to resolve conflict
(h) help - show this list
Let's briefly review each of these options before we go into detail on what each option means.
(p) postpone
Leave the file in a conflicted state for you to resolve after your update is complete.
(df) diff-full
Display the differences between the base revision and the conflicted file itself in unified diff format.
(e) edit
Open the file in conflict with your favorite editor, as set in the environment variable EDITOR.
(r) resolved
After editing a file, tell svn that you've resolved the conflicts in the file and that it should accept the current con-
tents—basically that you've “resolved” the conflict.
(mf) mine-full
Discard the newly received changes from the server and use only your local changes for the file under review.
(tf) theirs-full
Discard your local changes to the file under review and use only the newly received changes from the server.
(l) launch
Launch an external program to perform the conflict resolution. This requires a bit of preparation beforehand.
(h) help
Show the list of all possible commands you can use in interactive conflict resolution.
We'll cover these commands in more detail now, grouping them together by related functionality.
26
Draft Basic Usage Draft
Before deciding how to attack a conflict interactively, odds are that you'd like to see exactly what is in conflict, and the diff-full
command (df) is what you'll use for this:
…
Select: (p) postpone, (df) diff-full, (e) edit,
(h)elp for more options : df
--- .svn/text-base/[Link]-base Tue Dec 11 [Link] 2007
+++ .svn/tmp/[Link] Tue Dec 11 [Link] 2007
@@ -1 +1,5 @@
-Just buy a sandwich.
+<<<<<<< .mine
+Go pick up a cheesesteak.
+=======
+Bring me a taco!
+>>>>>>> .r32
…
The first line of the diff content shows the previous contents of the working copy (the BASE revision), the next content line is your
change, and the last content line is the change that was just received from the server (usually the HEAD revision). With this inform-
ation in hand, you're ready to move on to the next action.
If you wish to choose some combination of your local changes, you can use the “edit” command (e) to manually edit the file with
conflict markers in a text editor (determined by the EDITOR environment variable). Editing the file by hand in your favorite text
editor is a somewhat low-tech way of remedying conflicts (see the section called “Merging conflicts by hand” for a walkthrough),
so some people prefer to use fancy graphical merge tools instead.
To use a merge tool, you need to either set the SVN_MERGE environment variable or define the merge-tool-cmd option in
your Subversion configuration file (see the section called “Configuration Options” for more details). Subversion will pass four ar-
guments to the merge tool: the BASE revision of the file, the revision of the file received from the server as part of the update, the
copy of the file containing your local edits, and the merged copy of the file (which contains conflict markers). If your merge tool is
expecting arguments in a different order or format, you'll need to write a wrapper script for Subversion to invoke. After you've ed-
ited the file, if you're satisfied with the changes you've made, you can tell Subversion that the edited file is no longer in conflict by
using the “resolve” command (r).
If you decide that you don't need to merge any changes, but just want to accept one version of the file or the other, you can either
choose your changes (a.k.a. “mine”) by using the “mine-full” command (mf) or choose theirs by using the “theirs-full” command
(tf).
The C (for “Conflicted”) means that the changes from the server overlapped with your own, and now you have to manually choose
between them after the update has completed. When you postpone a conflict resolution, svn typically does three things to assist
you in noticing and resolving that conflict:
• Subversion prints a C during the update and remembers that the file is in a state of conflict.
27
Draft Basic Usage Draft
• If Subversion considers the file to be mergeable, it places conflict markers—special strings of text that delimit the “sides” of the
conflict—into the file to visibly demonstrate the overlapping areas. (Subversion uses the svn:mime-type property to decide
whether a file is capable of contextual, line-based merging. See the section called “File Content Type” to learn more.)
• For every conflicted file, Subversion places three extra unversioned files in your working copy:
[Link]
This is your file as it existed in your working copy before you updated your working copy—that is, without conflict markers.
This file has only your latest changes in it. (If Subversion considers the file to be unmergeable, the .mine file isn't created,
since it would be identical to the working file.)
[Link]
This is the file that was the BASE revision before you updated your working copy. That is, the file that you checked out before
you made your latest edits.
[Link]
This is the file that your Subversion client just received from the server when you updated your working copy. This file corres-
ponds to the HEAD revision of the repository.
Here OLDREV is the revision number of the file in your .svn directory, and NEWREV is the revision number of the repository
HEAD.
For example, Sally makes changes to the file [Link], but does not yet commit those changes. Meanwhile, Harry com-
mits changes to that same file. Sally updates her working copy before committing and she gets a conflict, which she postpones:
$ svn update
Conflict discovered in '[Link]'.
Select: (p) postpone, (df) diff-full, (e) edit,
(h)elp for more options : p
C [Link]
Updated to revision 2.
$ ls -1
[Link]
[Link]
[Link].r1
[Link].r2
At this point, Subversion will not allow Sally to commit the file [Link] until the three temporary files are removed:
If you've postponed a conflict, you need to resolve the conflict before Subversion will allow you to commit your changes. You'll do
this with the svn resolve command and one of several arguments to the --accept option.
If you want to choose the version of the file that you last checked out before making your edits, choose the base argument.
If you want to choose the version that contains only your edits, choose the mine-full argument.
If you want to choose the version that your most recent update pulled from the server (and thus discarding your edits entirely),
choose the theirs-full argument.
However, if you want to pick and choose from your changes and the changes that your update fetched from the server, merge the
conflicted text “by hand” (by examining and editing the conflict markers within the file) and then choose the working argument.
28
Draft Basic Usage Draft
svn resolve removes the three temporary files and accepts the version of the file that you specified with the --accept option,
and Subversion no longer considers the file to be in a state of conflict:
Here's an example. Due to a miscommunication, you and Sally, your collaborator, both edit the file [Link] at the same
time. Sally commits her changes, and when you go to update your working copy, you get a conflict and you're going to have to edit
[Link] to resolve the conflict. First, let's take a look at the file:
$ cat [Link]
Top piece of bread
Mayonnaise
Lettuce
Tomato
Provolone
<<<<<<< .mine
Salami
Mortadella
Prosciutto
=======
Sauerkraut
Grilled Chicken
>>>>>>> .r2
Creole Mustard
Bottom piece of bread
The strings of less-than signs, equals signs, and greater-than signs are conflict markers and are not part of the actual data in con-
flict. You generally want to ensure that those are removed from the file before your next commit. The text between the first two
sets of markers is composed of the changes you made in the conflicting area:
<<<<<<< .mine
Salami
Mortadella
Prosciutto
=======
The text between the second and third sets of conflict markers is the text from Sally's commit:
=======
Sauerkraut
Grilled Chicken
>>>>>>> .r2
Usually you won't want to just delete the conflict markers and Sally's changes—she's going to be awfully surprised when the sand-
wich arrives and it's not what she wanted. This is where you pick up the phone or walk across the office and explain to Sally that
you can't get sauerkraut from an Italian deli. 2 Once you've agreed on the changes you will commit, edit your file and remove the
2
And if you ask them for it, they may very well ride you out of town on a rail.
29
Draft Basic Usage Draft
conflict markers:
Now use svn resolve, and you're ready to commit your changes:
Note that svn resolve, unlike most of the other commands we deal with in this chapter, requires that you explicitly list any file-
names that you wish to resolve. In any case, you want to be careful and use svn resolve only when you're certain that you've fixed
the conflict in your file—once the temporary files are removed, Subversion will let you commit the file even if it still contains con-
flict markers.
If you ever get confused while editing the conflicted file, you can always consult the three files that Subversion creates for you in
your working copy—including your file as it was before you updated. You can even use a third-party interactive merging tool to
examine those three files.
$ svn update
Conflict discovered in '[Link]'.
Select: (p) postpone, (df) diff-full, (e) edit,
(h) help for more options: p
C [Link]
Updated to revision 2.
$ ls sandwich.*
[Link] [Link] [Link].r2 [Link].r1
$ svn resolve --accept theirs-full [Link]
Resolved conflicted state of '[Link]'
$
30
Draft Basic Usage Draft
Note that when you revert a conflicted file, you don't have to use svn resolve.
The svn commit command sends all of your changes to the repository. When you commit a change, you need to supply a log mes-
sage describing your change. Your log message will be attached to the new revision you create. If your log message is brief, you
may wish to supply it on the command line using the --message (-m) option:
However, if you've been composing your log message in some other text file as you work, you may want to tell Subversion to get
the message from that file by passing its filename as the value of the --file (-F) option:
If you fail to specify either the --message (-m) or --file (-F) option, Subversion will automatically launch your favorite ed-
itor (see the information on editor-cmd in the section called “Config”) for composing a log message.
If you're in your editor writing a commit message and decide that you want to cancel your commit, you can just quit
your editor without saving changes. If you've already saved your commit message, simply delete all the text, save
again, and then abort:
$ svn commit
Waiting for Emacs...Done
Log message unchanged or not specified
(a)bort, (c)ontinue, (e)dit
a
$
The repository doesn't know or care whether your changes make any sense as a whole; it checks only to make sure nobody else has
changed any of the same files that you did when you weren't looking. If somebody has done that, the entire commit will fail with a
message informing you that one or more of your files are out of date:
31
Draft Basic Usage Draft
(The exact wording of this error message depends on the network protocol and server you're using, but the idea is the same in all
cases.)
At this point, you need to run svn update, deal with any merges or conflicts that result, and attempt your commit again.
That covers the basic work cycle for using Subversion. Subversion offers many other features that you can use to manage your re-
pository and working copy, but most of your day-to-day use of Subversion will involve only the commands that we've discussed so
far in this chapter. We will, however, cover a few more commands that you'll use fairly often.
Examining History
Your Subversion repository is like a time machine. It keeps a record of every change ever committed and allows you to explore this
history by examining previous versions of files and directories as well as the metadata that accompanies them. With a single Sub-
version command, you can check out the repository (or restore an existing working copy) exactly as it was at any date or revision
number in the past. However, sometimes you just want to peer into the past instead of going into it.
Several commands can provide you with historical data from the repository:
svn log
Shows you broad information: log messages with date and author information attached to revisions and which paths changed
in each revision
svn diff
Shows line-level details of a particular change
svn cat
Retrieves a file as it existed in a particular revision number and displays it on your screen
svn list
Displays the files in a directory for any given revision
$ svn log
------------------------------------------------------------------------
r3 | sally | 2008-05-15 [Link] -0500 (Thu, 15 May 2008) | 1 line
Added include lines and corrected # of cheese slices.
------------------------------------------------------------------------
r2 | harry | 2008-05-14 [Link] -0500 (Wed, 14 May 2008) | 1 line
Added main() methods.
------------------------------------------------------------------------
r1 | sally | 2008-05-10 [Link] -0500 (Sat, 10 May 2008) | 1 line
Initial import
------------------------------------------------------------------------
Note that the log messages are printed in reverse chronological order by default. If you wish to see a different range of revisions in
a particular order or just a single revision, pass the --revision (-r) option:
32
Draft Basic Usage Draft
You can also examine the log history of a single file or directory. For example:
These will display log messages only for those revisions in which the working file (or URL) changed.
If you make a commit and immediately type svn log with no arguments, you may notice that your most recent commit
doesn't show up in the list of log messages. This is due to a combination of the behavior of svn commit and the default beha-
vior of svn log. First, when you commit changes to the repository, svn bumps only the revision of files (and directories) that
it commits, so usually the parent directory remains at the older revision (See the section called “Updates and commits are
separate” for an explanation of why). svn log then defaults to fetching the history of the directory at its current revision, and
thus you don't see the newly committed changes. The solution here is to either update your working copy or explicitly
provide a revision number to svn log by using the --revision (-r) option.
If you want even more information about a file or directory, svn log also takes a --verbose (-v) option. Because Subversion al-
lows you to move and copy files and directories, it is important to be able to track path changes in the filesystem. So, in verbose
mode, svn log will include a list of changed paths in a revision in its output:
$ svn log -r 8 -v
------------------------------------------------------------------------
r8 | sally | 2008-05-21 [Link] -0500 (Wed, 21 May 2008) | 1 line
Changed paths:
M /trunk/code/foo.c
M /trunk/code/bar.h
A /trunk/code/doc/README
Frozzled the sub-space winch.
------------------------------------------------------------------------
svn log also takes a --quiet (-q) option, which suppresses the body of the log message. When combined with --verbose
(-v), it gives just the names of the changed files.
After working with Subversion for a bit, most users will come across something like this:
33
Draft Basic Usage Draft
$ svn log -r 2
------------------------------------------------------------------------
$
At first glance, this seems like an error. But recall that while revisions are repository-wide, svn log operates on a path in the
repository. If you supply no path, Subversion uses the current working directory as the default target. As a result, if you're
operating in a subdirectory of your working copy and attempt to see the log of a revision in which neither that directory nor
any of its children was changed, Subversion will show you an empty log. If you want to see what changed in that revision,
try pointing svn log directly at the topmost URL of your repository, as in svn log -r 2 ^/.
In fact, it turns out that there are three distinct uses of svn diff:
$ svn diff
Index: [Link]
===================================================================
--- [Link] (revision 3)
+++ [Link] (working copy)
@@ -1,4 +1,5 @@
Be kind to others
Freedom = Responsibility
Everything in moderation
-Chew with your mouth open
+Chew with your mouth closed
+Listen when others are speaking
$
34
Draft Basic Usage Draft
@@ -1,4 +1,5 @@
Be kind to others
Freedom = Responsibility
Everything in moderation
-Chew with your mouth open
+Chew with your mouth closed
+Listen when others are speaking
$
A more convenient way of comparing one revision to the previous revision is to use the --change (-c) option:
Lastly, you can compare repository revisions even when you don't have a working copy on your local machine, just by including
the appropriate URL on the command line:
svn cat
35
Draft Basic Usage Draft
If you want to examine an earlier version of a file and not necessarily the differences between two files, you can use svn cat:
svn list
The svn list command shows you what files are in a repository directory without actually downloading the files to your local ma-
chine:
If you want a more detailed listing, pass the --verbose (-v) flag to get output like this:
The columns tell you the revision at which the file or directory was last modified, the user who modified it, the size if it is a file,
the date it was last modified, and the item's name.
The svn list command with no arguments defaults to the repository URL of the current working directory, not the
local working copy directory. After all, if you want a listing of your local directory, you could use just plain ls (or any
reasonable non-Unixy equivalent).
3
See? We told you that Subversion was a time machine.
36
Draft Basic Usage Draft
…
$ svn update -r 1729 # Updates an existing working copy to r1729
…
Many Subversion newcomers attempt to use the preceding svn update example to “undo” committed changes, but
this won't work as you can't commit changes that you obtain from backdating a working copy if the changed files
have newer revisions. See the section called “Resurrecting Deleted Items” for a description of how to “undo” a com-
mit.
Lastly, if you're building a release and wish to bundle up your files from Subversion but don't want those pesky .svn directories
in the way, you can use svn export to create a local copy of all or part of your repository sans .svn directories. As with svn up-
date and svn checkout, you can also pass the --revision (-r) option to svn export:
If you're likely to use a working copy again, there's nothing wrong with just leaving it on disk until you're ready to use it again, at
which point all it takes is an svn update to bring it up to date and ready for use.
However, if you're definitely not going to use a working copy again, you can safely delete the entire thing using whatever directory
removal capabilities your operating system offers. We recommend that before you do so you run svn status and review any
files listed in its output that are prefixed with a ? to make certain that they're not of importance.
This is exactly what svn cleanup does: it searches your working copy and runs any leftover to-do items, removing working copy
locks as it completes those operations. If Subversion ever tells you that some part of your working copy is “locked,” run svn
cleanup to remedy the problem. The svn status command will inform you about administrative locks in the working copy, too, by
displaying an L next to those locked paths:
37
Draft Basic Usage Draft
$ svn status
L somedir
M somedir/foo.c
$ svn cleanup
$ svn status
M somedir/foo.c
Don't confuse these working copy administrative locks with the user-managed locks that Subversion users create when using the
lock-modify-unlock model of concurrent version control; see the sidebar The Three Meanings of “Lock” for clarification.
But what happens if your collaborators move or delete a file that you are still working on? Maybe there was a miscommunication,
and one person thinks the file should be deleted, while another person still wants to commit changes to the file. Or maybe your col-
laborators did some refactoring, renaming files and moving around directories in the process. If you were still working on these
files, those modifications may need to be applied to the files at their new location. Such conflicts manifest themselves at the direct-
ory tree structure level rather than at the file content level, and are known as tree conflicts.
Prior to Subversion 1.6, tree conflicts could yield rather unexpected results. For example, if a file was locally modified, but
had been renamed in the repository, running svn update would make Subversion carry out the following steps:
• Delete the file at its old location, and if it had local modifications, keep an on-disk copy of the file at the old location. This
on-disk copy now appears as an unversioned file in the working copy.
When this situation arises, there is the possibility that the user makes a commit without realizing that local modifications
have been left in a now-unversioned file in the working copy, and have not reached the repository. This gets more and more
likely (and tedious) if the number of files affected by this problem is large.
Since Subversion 1.6, this and other similar situations are flagged as conflicts in the working copy.
As with textual conflicts, tree conflicts prevent a commit from being made from the conflicted state, giving the user the opportunity
to examine the state of the working copy for potential problems arising from the tree conflict, and resolving any such problems be-
fore committing.
4
Well, you could mark files containing conflict markers as resolved and commit them, if you really wanted to. But this is rarely done in practice.
38
Draft Basic Usage Draft
Your collaborator Harry has renamed the file bar.c to baz.c. You are still working on bar.c in your working copy, but you
don't know yet that the file has been renamed in the repository.
$ svn diff
Index: code/foo.c
===================================================================
--- code/foo.c (revision 4)
+++ code/foo.c (working copy)
@@ -3,5 +3,5 @@
int main(int argc, char *argv[])
{
printf("I don't like being moved around!\n%s", bar());
- return 0;
+ return 1;
}
Index: code/bar.c
===================================================================
--- code/bar.c (revision 4)
+++ code/bar.c (working copy)
@@ -1,4 +1,4 @@
const char *bar(void)
{
- return "Me neither!\n";
+ return "Well, I do like being moved around!\n";
}
Your changes are all based on revision 4. They cannot be committed because Harry has already checked in revision 5:
At this point, you need to run svn update. Besides bringing our working copy up to date so that you can see Harry's changes, this
39
Draft Basic Usage Draft
also flags a tree conflict so you have the opportunity to evaluate and properly resolve it.
$ svn update
C code/bar.c
A code/baz.c
U Makefile
Updated to revision 5.
Summary of conflicts:
Tree conflicts: 1
In its output, svn update signifies tree conflicts using a capital C in the fourth output column. svn status reveals additional details
of the conflict:
$ svn status
M code/foo.c
A + C code/bar.c
> local edit, incoming delete upon update
M code/baz.c
Note how bar.c is automatically scheduled for re-addition in your working copy, which simplifies things in case you want to keep
the file.
Because a move in Subversion is implemented as a copy operation followed by a delete operation, and these two operations cannot
be easily related to one another during an update, all Subversion can warn you about is an incoming delete operation on a locally
modified file. This delete operation may be part of a move, or it could be a genuine delete operation. Talking to your collaborators,
or, as a last resort, svn log, is a good way to find out what has actually happened.
Both foo.c and baz.c are reported as locally modified in the output of svn status. You made the changes to foo.c yourself,
so this should not be surprising. But why is baz.c reported as locally modified?
The answer is that despite the limitations of the move implementation, Subversion was smart enough to transfer your local edits in
bar.c into baz.c:
Local edits to the file bar.c, which is renamed during an update to baz.c, will only be applied to bar.c if your
working copy of bar.c is based on the revision in which it was last modified before being moved in the repository.
Otherwise, Subversion will resort to retreiving baz.c from the repository, and will not try to transfer your local
modifications to it. You will have to do so manually.
svn info shows the URLs of the items involved in the conflict. The left URL shows the source of the local side of the conflict,
while the right URL shows the source of the incoming side of the conflict. These URLs indicate where you should start searching
the repository's history for the change which conflicts with your local change.
40
Draft Basic Usage Draft
bar.c is now said to be the victim of a tree conflict. It cannot be committed until the conflict is resolved:
So how can this conflict be resolved? You can either agree or disagree with the move Harry made. In case you agree, you can de-
lete bar.c and mark the tree conflict as resolved:
If you do not agree with the move, you can delete baz.c instead, after making sure any changes made to it after it was renamed
are either preserved or not worth keeping. Do not forget to revert the changes Harry made to the Makefile. Since bar.c is
already scheduled for re-addition, there is nothing else left to do, and the conflict can be marked resolved:
41
Draft Basic Usage Draft
M Makefile
$ svn diff
Index: code/foo.c
===================================================================
--- code/foo.c (revision 5)
+++ code/foo.c (working copy)
@@ -3,5 +3,5 @@
int main(int argc, char *argv[])
{
printf("I don't like being moved around!\n%s", bar());
- return 0;
+ return 1;
}
Index: code/bar.c
===================================================================
--- code/bar.c (revision 5)
+++ code/bar.c (working copy)
@@ -1,4 +1,4 @@
const char *bar(void)
{
- return "Me neither!\n";
+ return "Well, I do like being moved around!\n";
}
Index: code/baz.c
===================================================================
--- code/baz.c (revision 5)
+++ code/baz.c (working copy)
@@ -1,4 +0,0 @@
-const char *bar(void)
-{
- return "Me neither!\n";
-}
Index: Makefile
===================================================================
--- Makefile (revision 5)
+++ Makefile (working copy)
@@ -1,2 +1,2 @@
foo:
- $(CC) -o $@ code/foo.c code/baz.c
+ $(CC) -o $@ code/foo.c code/bar.c
In either case, you have now resolved your first tree conflict! You can commit your changes and tell Harry during tea break about
all the extra work he caused for you.
Summary
Now we've covered most of the Subversion client commands. Notable exceptions are those dealing with branching and merging
(see Chapter 4, Branching and Merging) and properties (see the section called “Properties”). However, you may want to take a mo-
ment to skim through Chapter 9, Subversion Complete Reference to get an idea of all the different commands that Subversion
has—and how you can use them to make your work easier.
42
Draft Draft
But the Subversion feature set doesn't stop at “common version control operations.” It has other bits of functionality besides just
communicating file and directory changes to and from a central repository.
This chapter highlights some of Subversion's features that, while important, aren't part of the typical user's daily routine. It assumes
that you are familiar with Subversion's basic file and directory versioning capabilities. If you aren't, you'll want to first read
Chapter 1, Fundamental Concepts and Chapter 2, Basic Usage. Once you've mastered those basics and consumed this chapter,
you'll be a Subversion power user!
Revision Specifiers
As we described in the section called “Revisions”, revision numbers in Subversion are pretty straightforward—integers that keep
getting larger as you commit more changes to your versioned data. Still, it doesn't take long before you can no longer remember
exactly what happened in each and every revision. Fortunately, the typical Subversion workflow doesn't often demand that you
supply arbitrary revisions to the Subversion operations you perform. For operations that do require a revision specifier, you gener-
ally supply a revision number that you saw in a commit email, in the output of some other Subversion operation, or in some other
context that would give meaning to that particular number.
But occasionally, you need to pinpoint a moment in time for which you don't already have a revision number memorized or handy.
So besides the integer revision numbers, svn allows as input some additional forms of revision specifiers: revision keywords and
revision dates.
The various forms of Subversion revision specifiers can be mixed and matched when used to specify revision ranges.
For example, you can use -r REV1:REV2 where REV1 is a revision keyword and REV2 is a revision number, or
where REV1 is a date and REV2 is a revision keyword, and so on. The individual revision specifiers are independ-
ently evaluated, so you can put whatever you want on the opposite sides of that colon.
Revision Keywords
The Subversion client understands a number of revision keywords. These keywords can be used instead of integer arguments to the
--revision (-r) option, and are resolved into specific revision numbers by Subversion:
HEAD
The latest (or “youngest”) revision in the repository.
BASE
The revision number of an item in a working copy. If the item has been locally modified, this refers to the way the item ap-
pears without those local modifications.
COMMITTED
The most recent revision prior to, or equal to, BASE, in which an item changed.
PREV
The revision immediately before the last revision in which an item changed. Technically, this boils down to COMMITTED-1.
43
Draft Advanced Topics Draft
As can be derived from their descriptions, the PREV, BASE, and COMMITTED revision keywords are used only when referring to a
working copy path—they don't apply to repository URLs. HEAD, on the other hand, can be used in conjunction with both of these
path types.
Revision Dates
Revision numbers reveal nothing about the world outside the version control system, but sometimes you need to correlate a mo-
ment in real time with a moment in version history. To facilitate this, the --revision (-r) option can also accept as input date
specifiers wrapped in curly braces ({ and }). Subversion accepts the standard ISO-8601 date and time formats, plus a few others.
Here are some examples. (Remember to use quotes around any date that contains spaces.)
When you specify a date, Subversion resolves that date to the most recent revision of the repository as of that date, and then contin-
ues to operate against that resolved revision number:
44
Draft Advanced Topics Draft
If you specify a single date as a revision without specifying a time of day (for example 2006-11-27), you may think that
Subversion should give you the last revision that took place on the 27th of November. Instead, you'll get back a revision
from the 26th, or even earlier. Remember that Subversion will find the most recent revision of the repository as of the date
you give. If you give a date without a timestamp, such as 2006-11-27, Subversion assumes a time of [Link], so looking
for the most recent revision won't return anything on the 27th.
If you want to include the 27th in your search, you can either specify the 27th with the time ({"2006-11-27 23:59"}),
or just specify the next day ({2006-11-28}).
You can also use a range of dates. Subversion will find all revisions between both dates, inclusive:
Since the timestamp of a revision is stored as an unversioned, modifiable property of the revision (see the section
called “Properties”), revision timestamps can be changed to represent complete falsifications of true chronology, or
even removed altogether. Subversion's ability to correctly convert revision dates into real revision numbers depends
on revision datestamps maintaining a sequential ordering—the younger the revision, the younger its timestamp. If this
ordering isn't maintained, you will likely find that trying to use dates to specify revision ranges in your repository
doesn't always return the data you might have expected.
Properties
We've already covered in detail how Subversion stores and retrieves various versions of files and directories in its repository.
Whole chapters have been devoted to this most fundamental piece of functionality provided by the tool. And if the versioning sup-
port stopped there, Subversion would still be complete from a version control perspective.
In addition to versioning your directories and files, Subversion provides interfaces for adding, modifying, and removing versioned
metadata on each of your versioned directories and files. We refer to this metadata as properties, and they can be thought of as
two-column tables that map property names to arbitrary values attached to each item in your working copy. Generally speaking, the
names and values of the properties can be whatever you want them to be, with the constraint that the names must contain only AS-
CII characters. And the best part about these properties is that they, too, are versioned, just like the textual contents of your files.
You can modify, commit, and revert property changes as easily as you can file content changes. And the sending and receiving of
property changes occurs as part of your typical commit and update operations—you don't have to change your basic processes to
accommodate them.
Subversion has reserved the set of properties whose names begin with svn: as its own. While there are only a hand-
ful of such properties in use today, you should avoid creating custom properties for your own needs whose names be-
gin with this prefix. Otherwise, you run the risk that a future release of Subversion will grow support for a feature or
behavior driven by a property of the same name but with perhaps an entirely different interpretation.
Properties show up elsewhere in Subversion, too. Just as files and directories may have arbitrary property names and values at-
tached to them, each revision as a whole may have arbitrary properties attached to it. The same constraints apply—human-readable
45
Draft Advanced Topics Draft
names and anything-you-want binary values. The main difference is that revision properties are not versioned. In other words, if
you change the value of, or delete, a revision property, there's no way, within the scope of Subversion's functionality, to recover the
previous value.
Subversion has no particular policy regarding the use of properties. It asks only that you not use property names that begin with the
prefix svn:. That's the namespace that it sets aside for its own use. And Subversion does, in fact, use properties—both the ver-
sioned and unversioned variety. Certain versioned properties have special meaning or effects when found on files and directories,
or they house a particular bit of information about the revisions on which they are found. Certain revision properties are automatic-
ally attached to revisions by Subversion's commit process, and they carry information about the revision. Most of these properties
are mentioned elsewhere in this or other chapters as part of the more general topics to which they are related. For an exhaustive list
of Subversion's predefined properties, see the section called “Subversion Properties”.
While Subversion automatically attaches properties (svn:date, svn:author, svn:log, and so on) to revisions,
it does not presume thereafter the existence of those properties, and neither should you or the tools you use to interact
with your repository. Revision properties can be deleted programmatically or via the client (if allowed by the reposit-
ory hooks) without damaging Subversion's ability to function. So, when writing scripts which operate on your Sub-
version repository data, do not make the mistake of assuming that any particular revision property exists on a revi-
sion.
In this section, we will examine the utility—both to users of Subversion and to Subversion itself—of property support. You'll learn
about the property-related svn subcommands and how property modifications affect your normal Subversion workflow.
Why Properties?
Just as Subversion uses properties to store extra information about the files, directories, and revisions that it contains, you might
also find properties to be of similar use. You might find it useful to have a place close to your versioned data to hang custom
metadata about that data.
Say you wish to design a web site that houses many digital photos and displays them with captions and a datestamp. Now, your set
of photos is constantly changing, so you'd like to have as much of this site automated as possible. These photos can be quite large,
so as is common with sites of this nature, you want to provide smaller thumbnail images to your site visitors.
Now, you can get this functionality using traditional files. That is, you can have your [Link] and an im-
[Link] side by side in a directory. Or if you want to keep the filenames the same, you might have your
thumbnails in a different directory, such as thumbnails/[Link]. You can also store your captions and datestamps in
a similar fashion, again separated from the original image file. But the problem here is that your collection of files multiplies with
each new photo added to the site.
Now consider the same web site deployed in a way that makes use of Subversion's file properties. Imagine having a single image
file, [Link], with properties set on that file that are named caption, datestamp, and even thumbnail. Now your
working copy directory looks much more manageable—in fact, it looks to the casual browser like there are nothing but image files
in it. But your automation scripts know better. They know that they can use svn (or better yet, they can use the Subversion lan-
guage bindings—see the section called “Using the APIs”) to dig out the extra information that your site needs to display without
having to read an index file or play path manipulation games.
While Subversion places few restrictions on the names and values you use for properties, it has not been designed to
optimally carry large property values or large sets of properties on a given file or directory. Subversion commonly
holds all the property names and values associated with a single item in memory at the same time, which can cause
detrimental performance or failed operations when extremely large property sets are used.
Custom revision properties are also frequently used. One common such use is a property whose value contains an issue tracker ID
with which the revision is associated, perhaps because the change made in that revision fixes a bug filed in the tracker issue with
that ID. Other uses include hanging more friendly names on the revision—it might be hard to remember that revision 1935 was a
fully tested revision. But if there's, say, a test-results property on that revision with the value all passing, that's mean-
46
Draft Advanced Topics Draft
For all their utility, Subversion properties—or, more accurately, the available interfaces to them—have a major shortcoming:
while it is a simple matter to set a custom property, finding that property later is a whole different ball of wax.
Trying to locate a custom revision property generally involves performing a linear walk across all the revisions of the repos-
itory, asking of each revision, “Do you have the property I'm looking for?” Trying to find a custom versioned property is
painful, too, and often involves a recursive svn propget across an entire working copy. In your situation, that might not be as
bad as a linear walk across all revisions. But it certainly leaves much to be desired in terms of both performance and likeli-
hood of success, especially if the scope of your search would require a working copy from the root of your repository.
For this reason, you might choose—especially in the revision property use case—to simply add your metadata to the revi-
sion's log message using some policy-driven (and perhaps programmatically enforced) formatting that is designed to be
quickly parsed from the output of svn log. It is quite common to see the following in Subversion log messages:
But here again lies some misfortune. Subversion doesn't yet provide a log message templating mechanism, which would go a
long way toward helping users be consistent with the formatting of their log-embedded revision metadata.
Manipulating Properties
The svn program affords a few ways to add or modify file and directory properties. For properties with short, human-readable val-
ues, perhaps the simplest way to add a new property is to specify the property name and value on the command line of the svn
propset subcommand:
But we've been touting the flexibility that Subversion offers for your property values. And if you are planning to have a multiline
textual, or even binary, property value, you probably do not want to supply that value on the command line. So the svn propset
subcommand takes a --file (-F) option for specifying the name of a file that contains the new property value.
There are some restrictions on the names you can use for properties. A property name must start with a letter, a colon (:), or an un-
derscore (_); after that, you can also use digits, hyphens (-), and periods (.). 1
In addition to the propset command, the svn program supplies the propedit command. This command uses the configured editor
program (see the section called “Config”) to add or modify properties. When you run the command, svn invokes your editor pro-
gram on a temporary file that contains the current value of the property (or that is empty, if you are adding a new property). Then,
you just modify that value in your editor program until it represents the new value you wish to store for the property, save the tem-
1
If you're familiar with XML, this is pretty much the ASCII subset of the syntax for XML “Name”.
47
Draft Advanced Topics Draft
porary file, and then exit the editor program. If Subversion detects that you've actually changed the existing value of the property, it
will accept that as the new property value. If you exit your editor without making any changes, no property modification will oc-
cur:
$ svn propedit copyright calc/button.c ### exit the editor without changes
No changes to property 'copyright' on 'calc/button.c'
$
We should note that, as with other svn subcommands, those related to properties can act on multiple paths at once. This enables
you to modify properties on whole sets of files with a single command. For example, we could have done the following:
All of this property adding and editing isn't really very useful if you can't easily get the stored property value. So the svn program
supplies two subcommands for displaying the names and values of properties stored on files and directories. The svn proplist com-
mand will list the names of properties that exist on a path. Once you know the names of the properties on the node, you can request
their values individually using svn propget. This command will, given a property name and a path (or set of paths), print the value
of the property to the standard output stream.
There's even a variation of the proplist command that will list both the name and the value for all of the properties. Simply supply
the --verbose (-v) option.
The last property-related subcommand is propdel. Since Subversion allows you to store properties with empty values, you can't re-
move a property altogether using svn propedit or svn propset. For example, this command will not yield the desired effect:
48
Draft Advanced Topics Draft
You need to use the propdel subcommand to delete properties altogether. The syntax is similar to the other property commands:
Remember those unversioned revision properties? You can modify those, too, using the same svn subcommands that we just de-
scribed. Simply add the --revprop command-line parameter and specify the revision whose property you wish to modify. Since
revisions are global, you don't need to specify a target path to these property-related commands so long as you are positioned in a
working copy of the repository whose revision property you wish to modify. Otherwise, you can simply provide the URL of any
path in the repository of interest (including the repository's root URL). For example, you might want to replace the commit log
message of an existing revision. 2 If your current working directory is part of a working copy of your repository, you can simply
run the svn propset command with no target path:
$ svn propset svn:log "* button.c: Fix a compiler warning." -r11 --revprop
property 'svn:log' set on repository revision '11'
$
But even if you haven't checked out a working copy from that repository, you can still effect the property change by providing the
repository's root URL:
$ svn propset svn:log "* button.c: Fix a compiler warning." -r11 --revprop \
[Link]
property 'svn:log' set on repository revision '11'
$
Note that the ability to modify these unversioned properties must be explicitly added by the repository administrator (see the sec-
tion called “Commit Log Message Correction”). That's because the properties aren't versioned, so you run the risk of losing in-
formation if you aren't careful with your edits. The repository administrator can set up methods to protect against this loss, and by
default, modification of unversioned properties is disabled.
Users should, where possible, use svn propedit instead of svn propset. While the end result of the commands is
identical, the former will allow them to see the current value of the property that they are about to change, which
helps them to verify that they are, in fact, making the change they think they are making. This is especially true when
modifying unversioned revision properties. Also, it is significantly easier to modify multiline property values in a text
editor than at the command line.
2
Fixing spelling errors, grammatical gotchas, and “just-plain-wrongness” in commit log messages is perhaps the most common use case for the --revprop op-
tion.
49
Draft Advanced Topics Draft
As with file contents, your property changes are local modifications, made permanent only when you commit them to the reposit-
ory with svn commit. Your property changes can be easily unmade, too—the svn revert command will restore your files and dir-
ectories to their unedited states—contents, properties, and all. Also, you can receive interesting information about the state of your
file and directory properties by using the svn status and svn diff commands.
Notice how the status subcommand displays M in the second column instead of the first. That is because we have modified the
properties on calc/button.c, but not its textual contents. Had we changed both, we would have seen M in the first column, too.
(We cover svn status in the section called “See an overview of your changes”).
Property Conflicts
As with file contents, local property modifications can conflict with changes committed by someone else. If you update your
working copy directory and receive property changes on a versioned object that clash with your own, Subversion will report
that the object is in a conflicted state.
Subversion will also create, in the same directory as the conflicted object, a file with a .prej extension that contains the de-
tails of the conflict. You should examine the contents of this file so you can decide how to resolve the conflict. Until the con-
flict is resolved, you will see a C in the second column of svn status output for that object, and attempts to commit your local
modifications will fail.
To resolve property conflicts, simply ensure that the conflicting properties contain the values that they should, and then use
50
Draft Advanced Topics Draft
the svn resolved command to alert Subversion that you have manually resolved the problem.
You might also have noticed the nonstandard way that Subversion currently displays property differences. You can still use svn
diff and redirect its output to create a usable patch file. The patch program will ignore property patches—as a rule, it ignores any
noise it can't understand. This does, unfortunately, mean that to fully apply a patch generated by svn diff, any property modifica-
tions will need to be applied by hand.
Whenever you introduce a file to version control using the svn add or svn import commands, Subversion tries to assist by setting
some common file properties automatically. First, on operating systems whose filesystems support an execute permission bit, Sub-
version will automatically set the svn:executable property on newly added or imported files whose execute bit is enabled.
(See the section called “File Executability” later in this chapter for more about this property.)
Second, Subversion tries to determine the file's MIME type. If you've configured a mime-types-files runtime configuration
parameter, Subversion will try to find a MIME type mapping in that file for your file's extension. If it finds such a mapping, it will
set your file's svn:mime-type property to the MIME type it found. If no mapping file is configured, or no mapping for your
file's extension could be found, Subversion runs a very basic heuristic to determine whether the file contains nontextual content. If
so, it automatically sets the svn:mime-type property on that file to application/octet-stream (the generic “this is a
collection of bytes” MIME type). Of course, if Subversion guesses incorrectly, or if you wish to set the svn:mime-type prop-
erty to something more precise—perhaps image/png or application/x-shockwave-flash—you can always remove or
edit that property. (For more on Subversion's use of MIME types, see the section called “File Content Type” later in this chapter.)
Subversion also provides, via its runtime configuration system (see the section called “Runtime Configuration Area”), a more flex-
ible automatic property setting feature that allows you to create mappings of filename patterns to property names and values. Once
again, these mappings affect adds and imports, and can not only override the default MIME type decision made by Subversion dur-
ing those operations, but can also set additional Subversion or custom properties, too. For example, you might create a mapping
that says that anytime you add JPEG files—ones whose names match the pattern *.jpg—Subversion should automatically set the
svn:mime-type property on those files to image/jpeg. Or perhaps any files that match *.cpp should have
svn:eol-style set to native, and svn:keywords set to Id. Automatic property support is perhaps the handiest property-re-
lated tool in the Subversion toolbox. See the section called “Config” for more about configuring that support.
File Portability
Fortunately for Subversion users who routinely find themselves on different computers with different operating systems, Subver-
sion's command-line program behaves almost identically on all those systems. If you know how to wield svn on one platform, you
know how to wield it everywhere.
However, the same is not always true of other general classes of software or of the actual files you keep in Subversion. For ex-
ample, on a Windows machine, the definition of a “text file” would be similar to that used on a Linux box, but with a key differ-
ence—the character sequences used to mark the ends of the lines of those files. There are other differences, too. Unix platforms
have (and Subversion supports) symbolic links; Windows does not. Unix platforms use filesystem permission to determine execut-
ability; Windows uses filename extensions.
Because Subversion is in no position to unite the whole world in common definitions and implementations of all of these things,
the best it can do is to try to help make your life simpler when you need to work with your versioned files and directories on mul-
tiple computers and operating systems. This section describes some of the ways Subversion does this.
51
Draft Advanced Topics Draft
Various programs on most modern operating systems make assumptions about the type and format of the contents of a file
by the file's name, specifically its file extension. For example, files whose names end in .txt are generally assumed to be
human-readable; that is, able to be understood by simple perusal rather than requiring complex processing to decipher. Files
whose names end in .png, on the other hand, are assumed to be of the Portable Network Graphics type—not human-read-
able at all, and sensible only when interpreted by software that understands the PNG format and can render the information
in that format as a raster image.
Unfortunately, some of those extensions have changed their meanings over time. When personal computers first appeared, a
file named [Link] would have almost certainly been a plain-text file, just like today's .txt files. But by the mid-
1990s, you could almost bet that a file of that name would not be a plain-text file at all, but instead a Microsoft Word docu-
ment in a proprietary, non-human-readable format. But this change didn't occur overnight—there was certainly a period of
confusion for computer users over what exactly they had in hand when they saw a .DOC file. 3
The popularity of computer networking cast still more doubt on the mapping between a file's name and its content. With in-
formation being served across networks and generated dynamically by server-side scripts, there was often no real file per se,
and therefore no filename. Web servers, for example, needed some other way to tell browsers what they were downloading
so that the browser could do something intelligent with that information, whether that was to display the data using a pro-
gram registered to handle that datatype or to prompt the user for where on the client machine to store the downloaded data.
Eventually, a standard emerged for, among other things, describing the contents of a data stream. In 1996, RFC 2045 was
published. It was the first of five RFCs describing MIME. It describes the concept of media types and subtypes and recom-
mends a syntax for the representation of those types. Today, MIME media types—or “MIME types”—are used almost uni-
versally across email applications, web servers, and other software as the de facto mechanism for clearing up the file content
confusion.
For example, one of the benefits that Subversion typically provides is contextual, line-based merging of changes received from the
server during an update into your working file. But for files containing nontextual data, there is often no concept of a “line.” So, for
versioned files whose svn:mime-type property is set to a nontextual MIME type (generally, something that doesn't begin with
text/, though there are exceptions), Subversion does not attempt to perform contextual merges during updates. Instead, any time
you have locally modified a binary working copy file that is also being updated, your file is left untouched and Subversion creates
two new files. One file has a .oldrev extension and contains the BASE revision of the file. The other file has a .newrev exten-
sion and contains the contents of the updated revision of the file. This behavior is really for the protection of the user against failed
attempts at performing contextual merges on files that simply cannot be contextually merged.
The svn:mime-type property, when set to a value that does not indicate textual file contents, can cause some un-
expected behaviors with respect to other properties. For example, since the idea of line endings (and therefore, line-
ending conversion) makes no sense when applied to nontextual files, Subversion will prevent you from setting the
svn:eol-style property on such files. This is obvious when attempted on a single file target—svn propset will
error out. But it might not be as clear if you perform a recursive property set, where Subversion will silently skip over
files that it deems unsuitable for a given property.
Beginning in Subversion 1.5, users can configure a new mime-types-file runtime configuration parameter, which identifies
the location of a MIME types mapping file. Subversion will consult this mapping file to determine the MIME type of newly added
and imported files.
3
You think that was rough? During that same era, WordPerfect also used .DOC for their proprietary file format's preferred extension!
52
Draft Advanced Topics Draft
Also, if the svn:mime-type property is set, then the Subversion Apache module will use its value to populate the Content-
type: HTTP header when responding to GET requests. This gives your web browser a crucial clue about how to display a file
when you use it to peruse your Subversion repository's contents.
File Executability
On many operating systems, the ability to execute a file as a command is governed by the presence of an execute permission bit.
This bit usually defaults to being disabled, and must be explicitly enabled by the user for each file that needs it. But it would be a
monumental hassle to have to remember exactly which files in a freshly checked-out working copy were supposed to have their ex-
ecutable bits toggled on, and then to have to do that toggling. So, Subversion provides the svn:executable property as a way
to specify that the executable bit for the file on which that property is set should be enabled, and Subversion honors that request
when populating working copies with such files.
This property has no effect on filesystems that have no concept of an executable permission bit, such as FAT32 and NTFS. 4 Also,
although it has no defined values, Subversion will force its value to * when setting this property. Finally, this property is valid only
on files, not on directories.
This means that by default, Subversion doesn't pay any attention to the type of end-of-line (EOL) markers used in your files. Un-
fortunately, different operating systems have different conventions about which character sequences represent the end of a line of
text in a file. For example, the usual line-ending token used by software on the Windows platform is a pair of ASCII control char-
acters—a carriage return (CR) followed by a line feed (LF). Unix software, however, just uses the LF character to denote the end of
a line.
Not all of the various tools on these operating systems understand files that contain line endings in a format that differs from the
native line-ending style of the operating system on which they are running. So, typically, Unix programs treat the CR character
present in Windows files as a regular character (usually rendered as ^M), and Windows programs combine all of the lines of a Unix
file into one giant line because no carriage return-linefeed (or CRLF) character combination was found to denote the ends of the
lines.
This sensitivity to foreign EOL markers can be frustrating for folks who share a file across different operating systems. For ex-
ample, consider a source code file, and developers that edit this file on both Windows and Unix systems. If all the developers al-
ways use tools that preserve the line-ending style of the file, no problems occur.
But in practice, many common tools either fail to properly read a file with foreign EOL markers, or convert the file's line endings
to the native style when the file is saved. If the former is true for a developer, he has to use an external conversion utility (such as
dos2unix or its companion, unix2dos) to prepare the file for editing. The latter case requires no extra preparation. But both cases
result in a file that differs from the original quite literally on every line! Prior to committing his changes, the user has two choices.
Either he can use a conversion utility to restore the modified file to the same line-ending style that it was in before his edits were
made, or he can simply commit the file—new EOL markers and all.
The result of scenarios like these include wasted time and unnecessary modifications to committed files. Wasted time is painful
enough. But when commits change every line in a file, this complicates the job of determining which of those lines were changed
in a nontrivial way. Where was that bug really fixed? On what line was a syntax error introduced?
The solution to this problem is the svn:eol-style property. When this property is set to a valid value, Subversion uses it to de-
termine what special processing to perform on the file so that the file's line-ending style isn't flip-flopping with every commit that
comes from a different operating system. The valid values are:
4
The Windows filesystems use file extensions (such as .EXE, .BAT, and .COM) to denote executable files.
53
Draft Advanced Topics Draft
native
This causes the file to contain the EOL markers that are native to the operating system on which Subversion was run. In other
words, if a user on a Windows machine checks out a working copy that contains a file with an svn:eol-style property set
to native, that file will contain CRLF EOL markers. A Unix user checking out a working copy that contains the same file
will see LF EOL markers in his copy of the file.
Note that Subversion will actually store the file in the repository using normalized LF EOL markers regardless of the operating
system. This is basically transparent to the user, though.
CRLF
This causes the file to contain CRLF sequences for EOL markers, regardless of the operating system in use.
LF
This causes the file to contain LF characters for EOL markers, regardless of the operating system in use.
CR
This causes the file to contain CR characters for EOL markers, regardless of the operating system in use. This line-ending style
is not very common.
It's ludicrous to expect Subversion working copies to be somehow impervious to this kind of clutter and impurity. In fact, Subver-
sion counts it as a feature that its working copies are just typical directories, just like unversioned trees. But these not-
to-be-versioned files and directories can cause some annoyance for Subversion users. For example, because the svn add and svn
import commands act recursively by default and don't know which files in a given tree you do and don't wish to version, it's easy
to accidentally add stuff to version control that you didn't mean to. And because svn status reports, by default, every item of in-
terest in a working copy—including unversioned files and directories—its output can get quite noisy where many of these things
exist.
So Subversion provides two ways for telling it which files you would prefer that it simply disregard. One of the ways involves the
use of Subversion's runtime configuration system (see the section called “Runtime Configuration Area”), and therefore applies to
all the Subversion operations that make use of that runtime configuration—generally those performed on a particular computer or
by a particular user of a computer. The other way makes use of Subversion's directory property support and is more tightly bound
to the versioned tree itself, and therefore affects everyone who has a working copy of that tree. Both of the mechanisms use file
patterns (strings of literal and special wildcard characters used to match against filenames) to decide which files to ignore.
The Subversion runtime configuration system provides an option, global-ignores, whose value is a whitespace-delimited col-
lection of file patterns. The Subversion client checks these patterns against the names of the files that are candidates for addition to
version control, as well as to unversioned files that the svn status command notices. If any file's name matches one of the patterns,
Subversion will basically act as if the file didn't exist at all. This is really useful for the kinds of files that you almost never want to
version, such as editor backup files such as Emacs' *~ and .*~ files.
File patterns (also called globs or shell wildcard patterns) are strings of characters that are intended to be matched against fi-
lenames, typically for the purpose of quickly selecting some subset of similar files from a larger grouping without having to
explicitly name each file. The patterns contain two types of characters: regular characters, which are compared explicitly
against potential matches, and special wildcard characters, which are interpreted differently for matching purposes.
54
Draft Advanced Topics Draft
There are different types of file pattern syntaxes, but Subversion uses the one most commonly found in Unix systems imple-
mented as the fnmatch system function. It supports the following wildcards, described here simply for your convenience:
?
Matches any single character
*
Matches any string of characters, including the empty string
[
Begins a character class definition terminated by ], used for matching a subset of characters
You can see this same pattern matching behavior at a Unix shell prompt. The following are some examples of patterns being
used for various things:
File pattern matching is a bit more complex than what we've described here, but this basic usage level tends to suit the major-
ity of Subversion users.
When found on a versioned directory, the svn:ignore property is expected to contain a list of newline-delimited file patterns
that Subversion should use to determine ignorable objects in that same directory. These patterns do not override those found in the
global-ignores runtime configuration option, but are instead appended to that list. And it's worth noting again that, unlike the
global-ignores option, the patterns found in the svn:ignore property apply only to the directory on which that property is
set, and not to any of its subdirectories. The svn:ignore property is a good way to tell Subversion to ignore files that are likely
to be present in every user's working copy of that directory, such as compiler output or—to use an example more appropriate to
this book—the HTML, PDF, or PostScript files generated as the result of a conversion of some source DocBook XML files to a
more legible output format.
Subversion's support for ignorable file patterns extends only to the one-time process of adding unversioned files and
directories to version control. Once an object is under Subversion's control, the ignore pattern mechanisms no longer
55
Draft Advanced Topics Draft
apply to it. In other words, don't expect Subversion to avoid committing changes you've made to a versioned file
simply because that file's name matches an ignore pattern—Subversion always notices all of its versioned objects.
The Subversion svn:ignore property is very similar in syntax and function to the CVS .cvsignore file. In fact, if you
are migrating a CVS working copy to Subversion, you can directly migrate the ignore patterns by using the .cvsignore
file as input file to the svn propset command:
There are, however, some differences in the ways that CVS and Subversion handle ignore patterns. The two systems use the
ignore patterns at some different times, and there are slight discrepancies in what the ignore patterns apply to. Also, Subver-
sion does not recognize the use of the ! pattern as a reset back to having no ignore patterns at all.
The global list of ignore patterns tends to be more a matter of personal taste and ties more closely to a user's particular tool chain
than to the details of any particular working copy's needs. So, the rest of this section will focus on the svn:ignore property and
its uses.
In this example, you have made some property modifications to button.c, but in your working copy, you also have some unver-
sioned files: the latest calculator program that you've compiled from your source code, a source file named data.c, and a set
of debugging output logfiles. Now, you know that your build system always results in the calculator program being generated.
5 And you know that your test suite always leaves those debugging logfiles lying around. These facts are true for all working cop-
ies of this project, not just your own. And you know that you aren't interested in seeing those things every time you run svn status,
and you are pretty sure that nobody else is interested in them either. So you use svn propedit svn:ignore calc to add
some ignore patterns to the calc directory. For example, you might add this as the new value of the svn:ignore property:
calculator
debug_log*
After you've added this property, you will now have a local property modification on the calc directory. But notice what else is
different about your svn status output:
$ svn status
M calc
5
Isn't that the whole point of a build system?
56
Draft Advanced Topics Draft
M calc/button.c
? calc/data.c
Now, all that cruft is missing from the output! Your calculator compiled program and all those logfiles are still in your work-
ing copy; Subversion just isn't constantly reminding you that they are present and unversioned. And now with all the uninteresting
noise removed from the display, you are left with more intriguing items—such as that source code file data.c that you probably
forgot to add to version control.
Of course, this less-verbose report of your working copy status isn't the only one available. If you actually want to see the ignored
files as part of the status report, you can pass the --no-ignore option to Subversion:
As mentioned earlier, the list of file patterns to ignore is also used by svn add and svn import. Both of these operations involve
asking Subversion to begin managing some set of files and directories. Rather than force the user to pick and choose which files in
a tree she wishes to start versioning, Subversion uses the ignore patterns—both the global and the per-directory lists—to determine
which files should not be swept into the version control system as part of a larger recursive addition or import operation. And here
again, you can use the --no-ignore option to tell Subversion ignore its ignores list and operate on all the files and directories
present.
Even if svn:ignore is set, you may run into problems if you use shell wildcards in a command. Shell wildcards
are expanded into an explicit list of targets before Subversion operates on them, so running svn SUBCOMMAND * is
just like running svn SUBCOMMAND file1 file2 file3 …. In the case of the svn add command, this has an
effect similar to passing the --no-ignore option. So instead of using a wildcard, use svn add --force . to
do a bulk scheduling of unversioned things for addition. The explicit target will ensure that the current directory isn't
overlooked because of being already under version control, and the --force option will cause Subversion to crawl
through that directory, adding unversioned files while still honoring the svn:ignore property and global-ig-
nores runtime configuration variable. Be sure to also provide the --depth files option to the svn add com-
mand if you don't want a fully recursive crawl for things to add.
Keyword Substitution
Subversion has the ability to substitute keywords—pieces of useful, dynamic information about a versioned file—into the contents
of the file itself. Keywords generally provide information about the last modification made to the file. Because this information
changes each time the file changes, and more importantly, just after the file changes, it is a hassle for any process except the ver-
sion control system to keep the data completely up to date. Left to human authors, the information would inevitably grow stale.
For example, say you have a document in which you would like to display the last date on which it was modified. You could bur-
den every author of that document to, just before committing their changes, also tweak the part of the document that describes
when it was last changed. But sooner or later, someone would forget to do that. Instead, simply ask Subversion to perform keyword
substitution on the LastChangedDate keyword. You control where the keyword is inserted into your document by placing a
keyword anchor at the desired location in the file. This anchor is just a string of text formatted as $KeywordName$.
All keywords are case-sensitive where they appear as anchors in files: you must use the correct capitalization for the keyword to be
expanded. You should consider the value of the svn:keywords property to be case-sensitive, too—certain keyword names will
be recognized regardless of case, but this behavior is deprecated.
57
Draft Advanced Topics Draft
Subversion defines the list of keywords available for substitution. That list contains the following five keywords, some of which
have aliases that you can also use:
Date
This keyword describes the last time the file was known to have been changed in the repository, and is of the form $Date:
2006-07-22 [Link] -0700 (Sat, 22 Jul 2006) $. It may also be specified as LastChangedDate. Un-
like the Id keyword, which uses UTC, the Date keyword displays dates using the local time zone.
Revision
This keyword describes the last known revision in which this file changed in the repository, and looks something like
$Revision: 144 $. It may also be specified as LastChangedRevision or Rev.
Author
This keyword describes the last known user to change this file in the repository, and looks something like $Author: harry
$. It may also be specified as LastChangedBy.
HeadURL
This keyword describes the full URL to the latest version of the file in the repository, and looks something like $HeadURL:
[Link] $. It may be abbreviated as URL.
Id
This keyword is a compressed combination of the other keywords. Its substitution looks something like $Id: calc.c 148
2006-07-28 [Link]Z sally $, and is interpreted to mean that the file calc.c was last changed in revision 148 on
the evening of July 28, 2006 by the user sally. The date displayed by this keyword is in UTC, unlike that of the Date
keyword (which uses the local time zone).
Header
This keyword is similar to the Id keyword but contains the full URL of the latest revision of the item, identical to HeadURL.
Its substitution looks something like $Header: [Link] 148
2006-07-28 [Link]Z sally $.
Several of the preceding descriptions use the phrase “last known” or similar wording. Keep in mind that keyword expansion is a
client-side operation, and your client “knows” only about changes that have occurred in the repository when you update your work-
ing copy to include those changes. If you never update your working copy, your keywords will never expand to different values
even if those versioned files are being changed regularly in the repository.
Simply adding keyword anchor text to your file does nothing special. Subversion will never attempt to perform textual substitu-
tions on your file contents unless explicitly asked to do so. After all, you might be writing a document 6 about how to use
keywords, and you don't want Subversion to substitute your beautiful examples of unsubstituted keyword anchors!
To tell Subversion whether to substitute keywords on a particular file, we again turn to the property-related subcommands. The
svn:keywords property, when set on a versioned file, controls which keywords will be substituted on that file. The value is a
space-delimited list of keyword names or aliases.
For example, say you have a versioned file named [Link] that looks like this:
With no svn:keywords property set on that file, Subversion will do nothing special. Now, let's enable substitution of the
LastChangedDate keyword.
6
… or maybe even a section of a book …
58
Draft Advanced Topics Draft
Now you have made a local property modification on the [Link] file. You will see no changes to the file's contents
(unless you made some of your own prior to setting the property). Notice that the file contained a keyword anchor for the Rev
keyword, yet we did not include that keyword in the property value we set. Subversion will happily ignore requests to substitute
keywords that are not present in the file and will not substitute keywords that are not present in the svn:keywords property
value.
Immediately after you commit this property change, Subversion will update your working file with the new substitute text. Instead
of seeing your keyword anchor $LastChangedDate$, you'll see its substituted result. That result also contains the name of the
keyword and continues to be delimited by the dollar sign ($) characters. And as we predicted, the Rev keyword was not substi-
tuted because we didn't ask for it to be.
Note also that we set the svn:keywords property to Date Author, yet the keyword anchor used the alias
$LastChangedDate$ and still expanded correctly:
If someone else now commits a change to [Link], your copy of that file will continue to display the same substituted
keyword value as before—until you update your working copy. At that time, the keywords in your [Link] file will be re-
substituted with information that reflects the most recent known commit to that file.
Where's $GlobalRev$?
New users are often confused by how the $Rev$ keyword works. Since the repository has a single, globally increasing revi-
sion number, many people assume that it is this number that is reflected by the $Rev$ keyword's value. But $Rev$ expands
to show the last revision in which the file changed, not the last revision to which it was updated. Understanding this clears
the confusion, but frustration often remains—without the support of a Subversion keyword to do so, how can you automatic-
ally get the global revision number into your files?
To do this, you need external processing. Subversion ships with a tool called svnversion, which was designed for just this
purpose. It crawls your working copy and generates as output the revision(s) it finds. You can use this program, plus some
additional tooling, to embed that revision information into your files. For more information on svnversion, see the section
called “svnversion”.
Subversion 1.2 introduced a new variant of the keyword syntax, which brought additional, useful—though perhaps atypic-
al—functionality. You can now tell Subversion to maintain a fixed length (in terms of the number of bytes consumed) for the sub-
stituted keyword. By using a double colon (::) after the keyword name, followed by a number of space characters, you define that
fixed width. When Subversion goes to substitute your keyword for the keyword and its value, it will essentially replace only those
space characters, leaving the overall width of the keyword field unchanged. If the substituted value is shorter than the defined field
width, there will be extra padding characters (spaces) at the end of the substituted field; if it is too long, it is truncated with a spe-
cial hash (#) character just before the final dollar sign terminator.
For example, say you have a document in which you have some section of tabular data reflecting the document's Subversion
keywords. Using the original Subversion keyword substitution syntax, your file might look something like:
59
Draft Advanced Topics Draft
Now, that looks nice and tabular at the start of things. But when you then commit that file (with keyword substitution enabled, of
course), you see:
The result is not so beautiful. And you might be tempted to then adjust the file after the substitution so that it again looks tabular.
But that holds only as long as the keyword values are the same width. If the last committed revision rolls into a new place value
(say, from 99 to 100), or if another person with a longer username commits the file, stuff gets all crooked again. However, if you
are using Subversion 1.2 or later, you can use the new fixed-length keyword syntax and define some field widths that seem sane, so
your file might look like this:
You commit this change to your file. This time, Subversion notices the new fixed-length keyword syntax and maintains the width
of the fields as defined by the padding you placed between the double colon and the trailing dollar sign. After substitution, the
width of the fields is completely unchanged—the short values for Rev and Author are padded with spaces, and the long Date
field is truncated by a hash character:
The use of fixed-length keywords is especially handy when performing substitutions into complex file formats that themselves use
fixed-length fields for data, or for which the stored size of a given data field is overbearingly difficult to modify from outside the
format's native application (such as for Microsoft Office documents).
Be aware that because the width of a keyword field is measured in bytes, the potential for corruption of multibyte val-
ues exists. For example, a username that contains some multibyte UTF-8 characters might suffer truncation in the
middle of the string of bytes that make up one of those characters. The result will be a mere truncation when viewed
at the byte level, but will likely appear as a string with an incorrect or garbled final character when viewed as UTF-8
text. It is conceivable that certain applications, when asked to load the file, would notice the broken UTF-8 text and
deem the entire file corrupt, refusing to operate on the file altogether. So, when limiting keywords to a fixed size,
choose a size that allows for this type of byte-wise expansion.
Sparse Directories
By default, most Subversion operations on directories act in a recursive manner. For example, svn checkout creates a working
copy with every file and directory in the specified area of the repository, descending recursively through the repository tree until
the entire structure is copied to your local disk. Subversion 1.5 introduces a feature called sparse directories (or shallow checkouts)
that allows you to easily check out a working copy—or a portion of a working copy—more shallowly than full recursion, with the
freedom to bring in previously ignored files and subdirectories at a later time.
For example, say we have a repository with a tree of files and directories with names of the members of a human family with pets.
(It's an odd example, to be sure, but bear with us.) A regular svn checkout operation will give us a working copy of the whole tree:
60
Draft Advanced Topics Draft
Now, let's check out the same tree again, but this time we'll ask Subversion to give us only the topmost directory with none of its
children at all:
Notice that we added to our original svn checkout command line a new --depth option. This option is present on many of Sub-
version's subcommands and is similar to the --non-recursive (-N) and --recursive (-R) options. In fact, it combines,
improves upon, supercedes, and ultimately obsoletes these two older options. For starters, it expands the supported degrees of
depth specification available to users, adding some previously unsupported (or inconsistently supported) depths. Here are the depth
values that you can request for a given Subversion operation:
--depth empty
Include only the immediate target of the operation, not any of its file or directory children.
--depth files
Include the immediate target of the operation and any of its immediate file children.
--depth immediates
Include the immediate target of the operation and any of its immediate file or directory children. The directory children will
themselves be empty.
--depth infinity
Include the immediate target, its file and directory children, its children's children, and so on to full recursion.
Of course, merely combining two existing options into one hardly constitutes a new feature worthy of a whole section in our book.
Fortunately, there is more to this story. This idea of depth extends not just to the operations you perform with your Subversion cli-
ent, but also as a description of a working copy citizen's ambient depth, which is the depth persistently recorded by the working
copy for that item. Its key strength is this very persistence—the fact that it is sticky. The working copy remembers the depth you've
selected for each item in it until you later change that depth selection; by default, Subversion commands operate on the working
copy citizens present, regardless of their selected depth settings.
You can check the recorded ambient depth of a working copy using the svn info command. If the ambient depth is
anything other than infinite recursion, svn info will display a line describing that depth value:
61
Draft Advanced Topics Draft
Our previous examples demonstrated checkouts of infinite depth (the default for svn checkout) and empty depth. Let's look now at
examples of the other depth values:
As described, each of these depths is something more than only the target, but something less than full recursion.
We've used svn checkout as an example here, but you'll find the --depth option present on many other Subversion commands,
too. In those other commands, depth specification is a way to limit the scope of an operation to some depth, much like the way the
older --non-recursive (-N) and --recursive (-R) options behave. This means that when operating on a working copy of
some depth, while requesting an operation of a shallower depth, the operation is limited to that shallower depth. In fact, we can
make an even more general statement: given a working copy of any arbitrary—even mixed—ambient depth, and a Subversion
command with some requested operational depth, the command will maintain the ambient depth of the working copy members
while still limiting the scope of the operation to the requested (or default) operational depth.
In addition to the --depth option, the svn update and svn switch subcommands also accept a second depth-related option: -
-set-depth. It is with this option that you can change the sticky depth of a working copy item. Watch what happens as we take
our empty-depth checkout and gradually telescope it deeper using svn update --set-depth NEW-DEPTH TARGET:
As we gradually increased our depth selection, the repository gave us more pieces of our tree.
In our example, we operated only on the root of our working copy, changing its ambient depth value. But we can independently
change the ambient depth value of any subdirectory inside the working copy, too. Careful use of this ability allows us to flesh out
only certain portions of the working copy tree, leaving other portions absent altogether (hence the “sparse” bit of the feature's
name). Here's an example of how we might build out a portion of one branch of our family's tree, enable full recursion on another
branch, and keep still other pieces pruned (absent from disk).
62
Draft Advanced Topics Draft
$ rm -rf mom-empty
$ svn checkout [Link] mom-empty --depth empty
Checked out revision 1.
$ svn update --set-depth empty mom-empty/son
A mom-empty/son
Updated to revision 1.
$ svn update --set-depth empty mom-empty/daughter
A mom-empty/daughter
Updated to revision 1.
$ svn update --set-depth infinity mom-empty/daughter/granddaughter1
A mom-empty/daughter/granddaughter1
A mom-empty/daughter/granddaughter1/[Link]
A mom-empty/daughter/granddaughter1/[Link]
Updated to revision 1.
$
Fortunately, having a complex collection of ambient depths in a single working copy doesn't complicate the way you interact with
that working copy. You can still make, revert, display, and commit local modifications in your working copy without providing
any new options (including --depth and --set-depth) to the relevant subcommands. Even svn update works as it does else-
where when no specific depth is provided—it updates the working copy targets that are present while honoring their sticky depths.
You might at this point be wondering, “So what? When would I use this?” One scenario where this feature finds utility is tied to a
particular repository layout, specifically where you have many related or codependent projects or software modules living as sib-
lings in a single repository location (trunk/project1, trunk/project2, trunk/project3, etc.). In such scenarios, it
might be the case that you personally care about only a handful of those projects—maybe some primary project and a few other
modules on which it depends. You can check out individual working copies of all of these things, but those working copies are dis-
joint and, as a result, it can be cumbersome to perform operations across several or all of them at the same time. The alternative is
to use the sparse directories feature, building out a single working copy that contains only the modules you care about. You'd start
with an empty-depth checkout of the common parent directory of the projects, and then update with infinite depth only the items
you wish to have, like we demonstrated in the previous example. Think of it like an opt-in system for working copy citizens.
Subversion 1.5's implementation of shallow checkouts is good but does not support a couple of interesting behaviors. First, you
cannot de-telescope a working copy item. Running svn update --set-depth empty in an infinite-depth working copy
will not have the effect of discarding everything but the topmost directory—it will simply error out. Second, there is no depth value
to indicate that you wish an item to be explicitly excluded. You have to do implicit exclusion of an item by including everything
else.
Locking
Subversion's copy-modify-merge version control model lives and dies on its data merging algorithms—specifically on how well
those algorithms perform when trying to resolve conflicts caused by multiple users modifying the same file concurrently. Subver-
sion itself provides only one such algorithm: a three-way differencing algorithm that is smart enough to handle data at a granularity
of a single line of text. Subversion also allows you to supplement its content merge processing with external differencing utilities
(as described in the section called “External diff3”), some of which may do an even better job, perhaps providing granularity of a
word or a single character of text. But common among those algorithms is that they generally work only on text files. The land-
scape starts to look pretty grim when you start talking about content merges of nontextual file formats. And when you can't find a
tool that can handle that type of merging, you begin to run into problems with the copy-modify-merge model.
Let's look at a real-life example of where this model runs aground. Harry and Sally are both graphic designers working on the same
project, a bit of marketing collateral for an automobile mechanic. Central to the design of a particular poster is an image of a car in
need of some bodywork, stored in a file using the PNG image format. The poster's layout is almost finished, and both Harry and
Sally are pleased with the particular photo they chose for their damaged car—a baby blue 1967 Ford Mustang with an unfortunate
bit of crumpling on the left front fender.
Now, as is common in graphic design work, there's a change in plans, which causes the car's color to be a concern. So Sally up-
dates her working copy to HEAD, fires up her photo-editing software, and sets about tweaking the image so that the car is now
cherry red. Meanwhile, Harry, feeling particularly inspired that day, decides that the image would have greater impact if the car
63
Draft Advanced Topics Draft
also appears to have suffered greater impact. He, too, updates to HEAD, and then draws some cracks on the vehicle's windshield.
He manages to finish his work before Sally finishes hers, and after admiring the fruits of his undeniable talent, he commits the
modified image. Shortly thereafter, Sally is finished with the car's new finish and tries to commit her changes. But, as expected,
Subversion fails the commit, informing Sally that her version of the image is now out of date.
Here's where the difficulty sets in. If Harry and Sally were making changes to a text file, Sally would simply update her working
copy, receiving Harry's changes in the process. In the worst possible case, they would have modified the same region of the file,
and Sally would have to work out by hand the proper resolution to the conflict. But these aren't text files—they are binary images.
And while it's a simple matter to descri