Version control with Subversion how to set it up, use it, and save your sanity
Introduction
My life reduced to bullets Designing / developing sites since 1996 Independent consultant Using ColdFusion since version 5 Using Fusebox since version 2 Using XHTML/CSS since 2003 Using Subversion off/on October 2006 –More off than on…
Version control in a nutshell Central Repository of all code and changes made to it by anyone over time Developers get the latest copy, edit, and “check it back in” to the repository Changes made to the same file by different developers are merged If need be, you can go back to a previous version of the code
Why version control at all? A “Time Machine” for code Accounts for all changes Makes multi-version management easier The ultimate “CYA” tool
Source control vs. version control Source Code Management –More of a “total solution” that includes things like bug tracking, Wiki Version Control / Revision Control –This is what Subversion does
Not just for code, by the way… Design comps Project documentation Recipes Drafts of memos, letters, novels Anything you want to revise over time
Not just for teams, by the way I use it for my own stuff Revert to the previous version if I screw up Not that I screw up Yep. What, what are you looking at?
Version Control Concepts The “steps” of version control
Version Control Steps Create a repository of project files (code) CHECKOUT a working copy of the code to working directory Edit code
Version Control Steps COMMIT your changes back into the repository If someone else changed the same file as you, resolve differences to the changed files as needed (MERGE) UPDATE your working copy before continuing work the next time
Version control models
File sharing: the problem to avoid
Lock-Modify-Unlock
Copy-Modify-Merge
Copy-Modify-Merge (cont’d)
Options A quick look at what else is out there…
Microsoft Visual Source Safe Microsoft doesn’t use this Can cause files to become lost, corrupted Slow, not designed to work over internet $500/developer (?)
Concurrent Versioning System (CVS) Released in 1986 Free, open source Relatively easy to use Designed for a team environment
CVS Limitations Cannot move/rename files in CVS Directory move/changes aren’t versioned Poor unicode support –Doesn’t support non-ASCII characters well No versioning of symbolic links Binary files are saved in their entirety
Other commercial VCS’s Perforce –Free for up to 2 users; OSS –$800 per developer seat SourceHaven –$295/developer seat
Subversion
About Subversion Designed to replace CVS Began in 2000 Self-hosting in in Feb 2004 Current version: 1.4.5
Subversion benefits Directory versioning Filename versioning Atomic commits – all succeed or all fail Metadata – keywords/comment Networking support
Subversion benefits (cont’d) Delta compression –Saves differences between files (even binary) Branching / Tagging Well-defined API (e.g., Trac, TortoiseSVN, SCPlugin) Free!
Installation Setting it up…
Access options
SVNServe Daemon Easy, quick install –1-click setup (ok, it takes more than 1 click) All projects under one repository –You can create sub projects under this main repository, but it’s less elegant than separate repositories Listens on nonstandard port (3690) –Across internet, there could be a firewall issue
SVNServe Daemon / 1-click setup Ideal if you want to get up and running quick to play with Subversion Not ideal if you want to version more than one project and/or work across a network
Apache, WebDAV/DeltaV Allows you to work with an SVN repository anywhere in the world Uses or on port 80 – no firewall issues! Use authentication to restrict to username/password holders
Subversion Repository
My Repository
Physical repository
Virtual repository
Revision history
One repository, multiple projects index.cfm dsp_header.cfm dsp_footer.cfm index.cfm dsp_header.cfm dsp_footer.cfm
One repository for each project index.cfm dsp_header.cfm dsp_footer.cfm index.cfm dsp_header.cfm dsp_footer.cfm
Interacting with Subversion Some approaches…
Command line interface General client command line svn [command ] [arguments ] Read or update your working copy svn checkout svn update Make changes svn add svn delete svn copy svn move Commit your changes svn commit
TortoiseSVN client
SCPlugin client
Subclipse
Using Subversion Simple steps to save your sanity
Using Subversion Create the repository Import files into repository Checkout files as a working copy Change, commit, update Resolve conflicts (if needed)
Using Subversion Demo
Branching
Branching notes Branches are for the minority –Use for trying out new features, etc. You may branch from trunk or from branch –But don’t unless you really need to Can merge changes from the branch to trunk or vice-versa Don’t be scared!
Using Subversion and CF Old Way –We all update files on a “dev server” New Way –Check out code to a local working directory –Develop locally –Commit changes back –Deploy “build” from SVN to dev server
Tips and Best Practices Use version control Don’t break the tree –Don’t commit broken code or code that is not finished Don’t lock files unless you have a durned good reason to Explain commits completely and in plain language (use diff!)
Tips and Best Practices (cont’d) Update early and often Commit early and often –without breaking build When in doubt, resolve conflicts with fellow team members Version the stuff you control, not the stuff your code produces Use one repository per project Subversion != Backup
Thank You!
Copyright Info All Diagrams from Version Control with Subversion available from Copyright (c) Ben Collins-Sussman, Brian W. Fitzpatrick, C. Michael Pilato. This work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305,USA.
Resources
Sites SVN Project – SVN Forum –
Utilities SVN 1-click setup – Tortoise SVN – Subclipse – CVS Dude –
Books Version Control with Subversion – Pragmatic Version Control with Subversion –
Articles on version control/branching Subversion for Windows & Apache – Setting up a Subversion Server under Windows – /Setting_up_a_Subversion_Server_under_Windows.aspxhttp://blogs.vertigosoftware.com/teamsystem/archive/2006/01/16 /Setting_up_a_Subversion_Server_under_Windows.aspx Subversion branching quick start – Source Control HOWTO –