Overview of Using Subversion Locally

I was browsing through the recent CF-Talk threads and came upon a long one regarding source control. Naturally, Subversion was mentioned. There seemed to be a lot of back and forth, with some people not appearing to understand what/why you'd want to use Subversion. I thought I'd post my thoughts on Subversion, and also go over how I use it locally.

First, the underlying mechanics of Subversion (SVN) are very simple:

  • SVN holds a version history of all files in a repository.
  • You "get" the latest files by getting the latest versions from SVN.
  • You make changes to a file locally.
  • You "push" your changes back to the SVN repository.
  • Normally this goes through with no problem. Occasionally it will fail with an error because someone else edited the same file. In that case you can pull down the latest and...
  • If you and the other user did not both edit the same line of code, SVN will simply merge your changes together.
  • If you and the other user did edit the same line of code, you will be given a difference screen and asked to reconcile the changes.
  • Once the files are merged or reconciled, you push them back to SVN
  • Now everyone else using the repository has access to the latest code.

That's really all there is to it. It's not very complicated. 98% of the time you just pull down and push up your changes and everything is peachy. Sometimes you do have to reconcile changes to a file but it is pretty rare that two developers modify the same line(s) of code at the same time. If this happens a lot, it probably indicates the need for better coordination of what people are working on.

For reference, there is a whole book on the details of using SVN available online for free. It's slightly outdated but the vast majority of the ideas still apply.

For team development something like this is absolutely mandatory. Otherwise, attempting to integrate what everyone is working on into one codebase would be a nightmare. However, I also use SVN locally for keeping histories for word documents, test code, presentations, and just about anything else that I think has any importance. Being able to revert to previous versions when (WHEN) I make a mistake is a major relief. It's up there with having data backups for your system when your hard drive starts grinding.

If you want to try using SVN locally, its quite easy! Setting up SVN manually is actually kind of a pain. Luckily (at least if you're running Windows), you don't have to. There is a wonderful One Click Installer that sets up SVN locally and also installs the great Explorer extension TortoiseSVN which lets you perform SVN tasks right from Windows Explorer. (P.S. If there are similar setup packages for Mac or Linux please comment and let me know. Thx.)

OK, now one of the issues with SVN is that each repository is a complete entity. This means if you try to set up one giant uber-repository for everything on your system, you'll probably regret it. This is because versions in SVN apply to the entire repository. As you might imagine, this means you could change a file at revision 10, then go on changing other files for weeks to revision 20. Then, if you wanted to revert to revision 10, you will roll back all the other changes too.(I'm not fully explaining this, you CAN get individual versions of individual files, but if you need to roll back the whole repo this can be an issue). This would be annoying, and luckily it is also unnecessary.

You can set up multiple repositories for different things. I created a directory called svnrepos, and I set up my individual repositories within it:

OK, with repositories set up, the next question is how to connect to them. There are two ways to connect, one it to use file paths and one is to use the SVN network connector. I recommend using the SVN approach when possible. The One Click Setup program will install the necessary SVN Server service in Windows which should cover you.

You can add files to the repository by clicking on any directory, choosing "import" from the TortoiseSVN context menu, and simply pointing it at the URL for the desired repository:

Say I have a repository at C:\svnrepos\eCivis Documents and I have imported my files into this repository. Now I can use TortoiseSVN to browse that repository using the URL svn://localhost/eCivis Documents:

For me, the hardest part of learning to use SVN was just connecting to the darn thing. Once the repo is set up, you can simply check the files out into any directory you like. Just pick a target directory:

Pick which repository you want to use:

And watch SVN pull your files into that directory from the repository:

This has been a long post so I won't go into detail about how to check in changes. Suffice to say it's easy and done the same way, just right click on a file or folder that is changed (you can tell by the red exclamation point icon on it) and choose "SVN Commit". That's it. Same goes for getting the latest from SVN. Just right click on a file or folder and choose "SVN Update".

Lastly, if you use Eclipse there is a nice plugin called Subclipse that lets you connect to SVN repositories from directly within Eclipse. This is very handy and I use it every day.

I hope this has been informative to anyone intimidated by Subversion. I know it's no substitute for reading the SVN book, but hopefully this overview shows that there is nothing to be afraid of. As always, if you have comments or if any SVN gurus out there see things I'm doing incorrectly, please post below! Thanks.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Nice tutorial Ray; have you been able to get Subclipse and TortoiseSVN to play nicely with the same repo? If so can you tell me what versions of those clients are you running against what version of SVN. Thx!
# Posted By Mark Lapasa | 1/3/07 3:20 PM
I think you mean Brian not Ray! ;-) Sure, once the repo is set up you can access it either via Subclipse or via TortoiseSVN. I'm using the latest versions of all components. (Subversion 1.4.2, TSVN 1.4.1, Subclipse 1.0.4).
# Posted By Brian Kotek | 1/3/07 3:23 PM
Just a quick note about rollbacks, a repository can have mixed revisions, so you can easily "roll back" one file, by doing a merge backwards - svn merge /path/to/file.ext -r 20:10, that would copy back version 10 of that one file
# Posted By David HErman | 1/3/07 3:47 PM
Nice to see "eCivis Documents" being revisioned. Woo-hoo. Good post!
# Posted By Sami Hoda | 1/3/07 3:50 PM
Brian, a very timley post for me as I am getting ready to give a talk on Subversion at next week's MD-CFUG :) I had one question about Subclipse - I followed the directions to install it into Eclipse but it keeps saying that there is nothing to download. Anyone else having this problem?
# Posted By Christian Ready | 1/3/07 9:56 PM
Christian, you sure you're using the right URL, like:

http://subclipse.tigris.org/update_1.0.4

?
# Posted By Brian Kotek | 1/3/07 10:04 PM
Likewise, are you sure you don't already have it installed and just don't know it? You can check by going to Help>About>Plugin Details and check the version number.
# Posted By Brian Kotek | 1/3/07 10:05 PM
Well, that's the weird thing. Eclipse doesn't show it in the Help>About>Plugin Details window, but it's there in window I use to install it (Help>Software Updates>Find and Install). I guess that's because I tried once.

So I tried specifiying the version number and this time I get a 404 error when trying to install. Hmm...
# Posted By Christian Ready | 1/3/07 10:10 PM
My appologies Brian =S When I was the first to post at the bottom of this long entry, the first name I saw was ray in the footer. My bad
# Posted By Mark Lapasa | 1/4/07 12:23 AM
Looks like the problem was on my end. Turns out Eclipse thought I already had a more recent version of SVN installed. Thanks Brian for your offline help1
# Posted By Christian Ready | 1/4/07 9:17 PM
Brian, you can rollback by directory so your argument about sharing an uber directory isn't actually an issue. Hopefully (not that anybody would do thig), you would put each project/application in a sub-directory in your uber repository and you can just rollback changes for all files in that "project" directory and up. It won't affect other projects since you'll notice the log only shows revisions that affects file in your directory and up. The only thing is you share sequential revision number across your entire repository as you point out. Some people define this as an issue and some don't (honestly, I don't care).
# Posted By Peter J. Farrell | 1/5/07 9:59 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Blog Owner