Subversion for File Revision Management
This article was published by ComputorEdge, issue #2811, , as a feature article, in both their PDF edition (on pages 8-18) and their website.
Imagine that you are the lead engineer on a large software development project, and you are told that some of your colleagues have made numerous changes to the source code, in many files, and that those changes have broken the system, but your colleagues are unable to figure out why. Wouldn't it be terrific to be able to quickly and reliably roll back those now-unwanted changes, so the entire system is returned to its previous state, which worked perfectly? Or say that you are an author working alone on a nonfiction book, and you discover to your horror that all of the research that you recently integrated into your manuscript, is questionable and needs to be ripped out, but you can't remember where you made all the changes. If a genie gave you the ability to turn back the hands of time, and return your book to its previous and superior state, you would elect to do so in an instant.
These are but two examples of versioning problems, in which some sort of digital work — whether it be software, text, or anything similar — is being changed over time, and would benefit from being saved at various stages (typically referred to as "versions"), so that one could go back to an earlier version if needed. In other words, you want to be able to take a virtual snapshot of the product as a whole, and save that snapshot for possible future reference. In general, this is known as file "revision management"; in the case of software, in particular, it is usually referred to as "source control" or "source code management" (SCM).
Given the critical importance of revision management in developing a wide range of digital products, it should be no surprise that, over the years, a number of revision applications have been created to do just that. Fortunately, many of them are open source, which basically means that the application can be used free of charge, and the source code that comprises it is freely available, in case anyone is interested in seeing how it works, or making changes to it, or confirming that it does not contain security flaws or spyware.
The types of revision applications are as varied as the needs that they fulfill, ranging from simple applications that are a breeze to install but limited in functionality, all the way up to extremely complex SCM systems that require expert installation and babysitting. An example of the latter group is IBM's Rational ClearCase, which is used by the kinds of software development projects involving millions of lines of source code, and requiring multiple ClearCase administrators. But for those of us who want a far cheaper and understandable application, there are several free ones available. In this article, I will examine Subversion (a.k.a. SVN).
Subversion is one of the most respected file revision applications on the market, with a reputation for offering several advantages over alternative products: ease of installation, greater stability, and better file moving, renaming, and deleting capabilities. As a result, it may be the most widely adopted versioning system around, and is in continuous use by large corporations and major software development projects. It runs on Windows, Mac OS X, and all mainstream Linux distributions.
The standard Subversion package can be thought of as a versioning server, and thus needs to be used in conjunction with a client program. Several options are available for all of the major operating systems, and I will get into the details of that later. On a related note, much of the Subversion documentation mentions the Apache Web server, which can be used as its repository-side network service. For most readers interested in source code versioning, Apache is probably already installed and in use (for viewing websites locally). Windows users would need to install it manually, while Mac OS X and most if not all Linux distributions come with Apache preinstalled. But Apache is not a requirement, because Subversion includes a built-in server, Svnserve, which may not offer as many capabilities as Apache, but is adequate for most users, and is simple and lightweight.
In order to install Subversion on your own computer, visit the aforementioned website, and click on the blue download link corresponding to your operating system. (In this article, I will be using the Windows version.) You can also download the source code, if you want to compile it yourself. But in this example I will be using the binary (i.e., the precompiled executable program).
Clicking that link takes you to the binary packages section of the download page.
Select the second choice in the Windows section, which takes you to the "Documents & files: Windows Apache 2.2.x" page, where you can choose the latest version, which as of this writing is 1.6.6. The file name is Setup-Subversion-1.6.6.msi, whose extension indicates that it is a Microsoft Installer file. Save the file to a location on your computer where you can find it, and once the download process is complete, open the installation file. A welcome dialog box should be displayed.
Click through the subsequent dialog box, which contains some noncritical project information.
At the next dialog box, you can specify the destination folder, or use their default (C:\Program Files\Subversion\), which I will do.
At this point you are ready to install the product.
The installation should only take a few seconds, and ends with a completion dialog box that contains information only of interest to any poor soul still using Windows 95, 97, or Millennium.
The installer does not add an icon to your Windows desktop or system tray, but it does add an entry in your Start menu.
The Subversion menu does not contain an entry for running the program, as one would see for a typical Windows application. As mentioned earlier, a client program is needed to serve as the user interface. Before you install that client program, start the aforementioned Svnserve by opening a DOS prompt and running the command: C:\Program Files\Subversion\bin\svnserve.exe --daemon
On the Subversion home page, there is a section for third-party clients, one of which is TortoiseSVN. For Windows users, this is the recommended — and possibly only available — front-end for talking to the Subversion back-end.
In the "Latest Version" section, click on the "download page" link.
For version 1.6.6, choose either the 32-bit or 64-bit edition, depending upon your PC's configuration. I will be using the former. Download and then open the installer file.
The various dialog boxes that are presented to you by the installer are very much like those of Subversion itself, so they will not be included here. You can accept the default values for each dialog box. Note that there can be a delay before the installer begins unpacking the files and writing them to the installation folder, so be patient. Once the file writing begins, it should take less than a minute to complete. At that point, after you click the "Finish" button, you will be informed that you need to restart your computer. Be sure to save all of your work in any open applications before clicking the "Yes" button, which begins rebooting your computer.
Putting That Subversive Turtle to Work
Your Windows Start menu should contain a new TortoiseSVN menu.
If you were to select the "TortoiseSVN" entry in the menu, the program simply displays a dialog box informing you that TortoiseSVN is not a stand-alone application, but instead works as an extension of Windows Explorer.
Now that Subversion and TortoiseSVN are installed on your system, you can use them to begin tracking revisions to files. First, you need to create a repository, which is somewhat like a file server, but is different in that it remembers every change that you ever write to it (each one is known as a "commit"). For purposes of illustration, let's create a simple repository: First, you create a folder, in this case named C:\repository. Within Windows Explorer, select C:\repository, right-click on the folder, and in the folder's context menu, choose the menu item TortoiseSVN > "Create repository here".
Four folders and two files are created in that folder.
Be sure not to modify or delete those files or folders, unless you know exactly what you're doing. You can view the contents of any repository by displaying its folder's context menu, and choosing TortoiseSVN > Repo-browser.
Now you are set up to import a folder — which can contain unlimited files and subfolders — into your repository. For simplicity's sake, I will use a single text file in a folder: C:\test\sample_file.txt. From the folder's context menu, choose TortoiseSVN > Import, and click the OK button.
TortoiseSVN shows that the sample file was correctly checked in.
To check-out the folder in order to make changes to any file contained within it, right-click on the repository folder, and choose "SVN Checkout".
The second field in the dialog box allows you to change the location where the checkout files will reside. Naturally, after making changes to them, you will want to check them back into the repository. You can then use the features of TortoiseSVN at any time to view the differences between any two versions.
Space limitations of this article do not allow us to go into the details of branching, tagging, folder versioning, network layers, icon overlays, and all the other powerful features available in Subversion and TortoiseSVN. If you wish to learn more about this robust solution for tracking changes to files and directories, you are encouraged to read the online help information, and see if these programs will serve your needs for revision management.