Class 12 – Intro to Using a Subversion Client
Monday, May 3rd, 2010The following is a brief example of working within a Subversion version control setup. In this case, we will assume that some overworked server administrator (i.e. me) has set up a repository where a large amount of source code magically is stored and backed up by Subversion, a popular version control system. In our case, the source code is all the example files from this course.
Read the overview of Subversion concepts in the post linked above before proceeding.
The hypothetical setup
The under appreciated developers (i.e. you), just need a way to checkout (i.e. download) the latest copy of the code from the repository (i.e. the server), make some changes to some of the code, and then commit (i.e. upload) your changes back to the repository. You do this so that we can track the changes made to the files and so that everyone else can download new-and-improved version of the source code that you created at their leisure.
Using source control keeps the source code safe from being accidentally deleted, prevents two developers from overwriting the same file at the same time, and it keeps a record of who changed what and when they did it so that your manager (i.e. me) can make sure his minions (i.e. you) are doing their assigned jobs in a timely manner.
Think of it as a backup system with benefits.
The Subversion client
To interface with our Subversion repository, we use a Subversion client application. Just as we use web browser clients to surf web pages on the server, and we use file transfer clients to browse files on the server, we also use Subversion clients to manipulate version-controlled files on the Subversion server.
The popular client applications for Subversion provide nice graphical user interfaces for you to use so you don’t have to manually send Subversion commands to our Subversion repository on the Linux server. Popular Subversion clients that I currently recommend are TortoiseSVN for the PC and SvnX for the Mac. Both add extra Subversion-related options to the context menu (right click menu on PC; control-click on the Mac) within Windows Explorer and Mac Finder, respectively.
Make sure you have one of these clients installed before following the instructions below.
Getting a working copy of the code
To get a “working copy” of the code, meaning to download the latest version of all the code from the Subversion server, you make a folder on your client machine where you want to store your copy of the code.
Right click on the folder name and select “Checkout” from the new options that the Subversion client added to your context menu.
Enter the URL of the repository: “http://svn.onepotcooking.com/webdev/trunk” and the usual username/password in the screen that pops up.
Successfully logging in will checkout (i.e. download) a full copy of all the latest source code in the repository and put it into the selected folder on your client. You will see that the folder and files on your computer have special icons next to them indicating their version control status.
The green checkmark icon means that you have not modified any of the files in this folder since last downloading the files from the Subversion server.
You’re now ready to make changes to some code.
Make some changes
Go into the source code you just checked out on your client and open up the file class12/subversion/index.html in your text editor of choice and make some changes to that file.
Update the code
You’re almost ready to “commit” (i.e. upload) your changes back to the repository. But first you have to make sure nobody else changed the same files as you between the time you last downloaded them from the repository and the time you finished editing them.
If two people edit the same file at the same time, you wouldn’t want one person to overwrite the other’s work. So Subversion automatically checks for conflicts. If they are easy to solve, such as if one person edited the top of a file while the other person edited the bottom, Subversion merges the two copies of the file automatically. If the conflicts are complicated, Subversion will as you to manually merge the two versions of the conflicted file.
So update your working copy with a fresh copy of the latest code from the repository by using the Subversion client’s update command on the project folder. This will update everything inside of the folder and check for conflicts between the changes you have made and the changes others have made.
Commit your changes
Once any conflicts have been resolved, you are ready to commit your code to the repository.
Use the Subversion client’s commit option to upload your copy of the entire folder to the repository for safe keeping. You can also just commit specific files rather than the whole folder, but for now we’ll upload any changes we made to any files in the folder to keep things simpler. Subversion is smart enough to only upload the files that have been modified anyway.
Add a file
Now let’s say you want to add a new file to this project. On your client computer, create a new file in the class12/subversion folder called <your_name>.html, where <your_name> is replaced with your first name and last initial, of course.
By creating this file on your client machine, it is not yet added into the version control system unless you make it so. To add it to the Subversion repository, you need to use the Subversion “add” command. So right-click on the file and click the Subversion add command.
Adding a new file is just like making any other change, whether it be adding, deleting, or modifying a file on your client. The changes you make on your client are not uploaded to the server repository until you commit them using Subversion’s commit command.
So now go ahead and commit the changes you’ve made.
The next time anyone else updates their “working copy” of the code using the Subversion update command, they will see this new file has been added. In other words, if I don’t see your file the next time I update, I will know you didn’t follow this tutorial! I should have forced you to use this technology from the beginning of this course.
Further changes
From this point onward, always download the latest copy of all files using Subversion’s update command on the project folder before you make major changes. This reduces the chance that your work will have a conflict with another developer’s work, and it will reduce any chance that you are working on an outdated copy of a file.





