Keeping your code managed with an SVN

For those that don’t know what an SVN is, it’s a successor to a Concurrent Versions System (CVS), but what is that and how can it help me?

What an SVN does
When I would do just small changes to a site or a small piece of code, I would usually just make a copy of the original file, name it (filename)-good.ext, by adding -good to the name I always had at least the last version that worked, but the more and more you start working with code, you start to understand that you may need a file from 3 versions back, of if a bug is found, or a problem occurs, you need to go back to a certain date to see what was done and undo it. This is what CVS’s and SVN’s do.

How do you use an SVN?
Once an SVN is installed and setup, the server now has a complete list of the files you want to keep, watch and backup. You as the user will then checkout all these files to a directory on your own PC (or another directory, if the SVN server is on your own system). Now, lets say I work all day on a file for my website, I save the file and once saved I’ll see a small red mark next to that file in my directory, this tells me the file has been changed and needs to be rechecked in to the server. This is called committing, when you commit a file to the server, the file is given a revision number and saved to the server, along with the file you can also create a log for that file saying what you changed, why it was changed and usually by double clicking the file you can see your new file and the older file, with all differences being highlighted.
If you ever need an older file, the SVN has a list of the files and their revisions, you can look at each file, find the one you need by looking at code or date checked in and either check it out to a different directory, to work on or you can make that the new current file. This is where the log files help, you can see what you changed and most importantly, why.

How Do I setup an SVN?
There are two parts of an SVN, the server and Client. Most clients will work with any server, so why not find the easiest of each.
For the server, you can install the server on your own machine or you can find an old machine (even though it’s called a server it doesn’t take much computing power). I pulled an old machine from my closet that had WinXP installed and installed the server on it. Since it is a server, most SVN’s use Apache for the server part, you can install all the parts separate or take the easy route and use VisualSVN, which includes Subversion, Apache and a management console, all that you need for an SVN server.
For the client I chose, TortoiseSVN, again very easy to install on Windows. With a great FAQ’s and walkthroughs, I was able to have everything installed in about 2 hours, it took me a bit longer since I was setting up the server for multiple people and multiple programs that have their own repository.
I’m sure most programmers have their favorite CVS or SVN, these are just the server and client I chose, there are many more out there, some work better on different OS’s. My SVN has saved my butt a couple times, if you even think you may need this, install it and you’ll never go back to having multiple copies of each file laying around in different directories.

Oh did I mention, it’s FREE! 😉

Technorati Tags: , , , , , , , ,


Leave a Reply