PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1

C H A P T E R 17


■ ■ ■


Version Control with Subversion


All disasters have their tipping point, the moment at which order finally breaks down and events simply
spiral out of control. Do you ever find yourself in projects like that? Are you able to spot that crucial
moment? Perhaps it’s when you make “just a couple of changes” and find that you have brought
everything crashing down around you (and even worse, you’re not quite sure how to get back to the
point of stability you have just destroyed). It could be when you realize that three members of your team
have been working on the same set of classes and merrily saving over each other’s work. Or perhaps it’s
when you discover that a bug fix you have implemented twice has somehow disappeared from the
codebase yet again. Wouldn’t it be nice if there was a tool to help you manage collaborative working,
allowing you to take snapshots of your projects and roll them back if necessary, and to merge multiple
strands of development? In this chapter, we look at Subversion, a tool that does all that and more.
This chapter will cover



  • Basic configuration: Some tips for setting up Subversion

  • Importing: Starting a new project

  • Committing changes: Saving your work to the repository

  • Updating: Merging other people’s work with your own

  • Branching: Maintaining parallel strands of development


Why Use Version Control?


If it hasn’t already, version control will change your life (if only your life as a developer). How many
times have you reached a stable moment in a project, drawn a breath, and plunged onward into
development chaos once again? How easy was it to revert to the stable version when it came time to
demonstrate your work in progress? Of course, you may have saved a snapshot of your project when it
reached a stable moment, probably by duplicating your development directory. Now, imagine that your
colleague is working on the same codebase. Perhaps he has saved a stable copy of the code as you have.
The difference is that his copy is a snapshot of his work, not yours. Of course, he has a messy
development directory too. So you have four versions of your project to coordinate. Now imagine a
project with four programmers and a web UI developer. You’re looking pale. Perhaps you would like to
lie down?
Subversion exists exclusively to address this problem. Using Subversion, all your developers check
out their own copies of the codebase from a central repository. Whenever they reach a stable point in
their code, they update their copies. This merges any changes in the shared code with their own recent
work. After they fix any conflicts, they can check their new stable versions back into the shared
repository. There is now only one authoritative source of code in your project. The fact that each

Free download pdf