Introduction to Subversion

Subversion is a source code version control system (VCS), also known as version control. Version control systems are at the heart of how programmers manage and share source code.

1. Why Use Source Version Control?

A source code repository is a bit like the shared folders that are provided by services like Dropbox, Box, and Google Drive. You can save files and folders and share them with other users in various ways. Some of these tools even track allow you to undo and redo changes and see how files have changed over time. These are useful tools, and a great way to collaborate with others in a variety of different scenarios. So it’s normal to wonder: what’s different about source version control?

Compared to tools like Dropbox, source version control provides programmers with several important advantages.

1.1. Versioning Entire Projects

First, version control systems track the version of all the files in each repository, rather than individual files separately. Programming frequently involves making a set of changes to a group of files that together accomplish something—like fixing a bug or adding a new feature. So when you commit your work using Subversion, it remembers the state of all the files in your repository at that time. This allows you to compare what your project looked like at different times, and undo an entire set of changes that might have caused a problem.

Note that this also means that Subversion does not track all the changes you save to a file. Unless you commit your changes, they are not saved to your repository. This may seem like an annoyance—after all, systems like Dropbox will sync your files every time you save them.

But when programming this turns out to be a huge advantage. Let’s say you save a version of Foo.java to test—but it contains errors. Now if you are using Dropbox, everyone has that broken version of the file. But if you are using Subversion, you can test your code, notice the errors, and fix them before committing.

A Subversion 1 commit is really their equivalent of the save operation. Regardless of whether you save your files in Eclipse or any other way, you have to commit them to your repository before it will save and remember them.

1.2. Version Comments

Version control systems also allow you to add your own notes to each commit. This is called a comment. Comments should summarize what changes are included in the new version of the project. Good comments are extremely helpful to other developers that are trying to understand how the code is evolving. All version control systems have ways to view the list of version with their comments. This can be useful when you want to see how things have changed, or back up and use an older version of a project where some feature was working that isn’t any more.

1.3. Merging Changes

Second, version control systems help you merge changes made by different developers—even to the same file. Say that Foo.java has 1000 lines. Alice makes a change at the top of the file. Concurrently, Bob makes a change to the bottom of the file. Systems like Dropbox will typically force you to address this conflict by choosing either Alice’s version of the file or Bob’s. But version control systems can frequently automatically merge non-overlapping changes to source code files—allowing you to choose to combine the changes from Alice with the changes from Bob. When you are working in large teams on large software projects, this capability is extremely handy.

2. Introduction to Subversion

Now that you agree that using version control is useful, let’s go through the basics of how to use Subversion.

Subversion organizes your files into a repository. A repository can contain any number of files organized any way you like. But a single repository usually contains all of the code used by a single project. For CS 125, you will use a single repository that holds all of the Java source code files that you will use this semester—both in labs and during the machine problems 2.

For CS 125 your subversion repository is stored on a remote server: https://subversion.ews.illinois.edu/. So the steps required to use Subversion effectively—your version control workflow—consist of adding Eclipse projects to your repository, committing changes to your files, and adding new files to your repository. But first we have to configure Eclipse to use your CS 125 subversion repository.

2.1. Connecting to Your Repository

All repositories for this semester are stored as subfolders under https://subversion.ews.illinois.edu/svn/fa17-cs125/. To get the URL for your repository, simply add your Illinois NetID. Here are a few examples:

Hopefully by now you get the pattern. Now that you have the link to your Subversion repository ready, let’s set up Eclipse to use it:

  1. Start by opening the Eclipse SVN Repository Perspective: "Window → Perspective → Open Perspective → Other…​ → SVN Repository Explorer".

  2. Now select "New → Repository Location".

  3. Insert the link to your Subversion repository that you computed above.

  4. Eclipse will prompt you for your Illinois AD username (NetID) and password. Enter them. You may want to choose to save your credentials so that you are not repeatedly prompted for your username and password.

At this point you can view your repository. To see what it currently contains, right click on it and click "Refresh".

2.2. Adding Projects to Your Repository

When you start a new project in Eclipse, the files are initially stored locally and not synchronized with your remote repository. To add a project to your repository and begin tracking changes using Subversion, follow the following steps:

  1. Make sure that you are in the Java perspective: "Window → Perspective → Open Perspective → Java).

  2. Click on "Team → Share Project". Select the SVN option and click next.

  3. Your CS 125 repository that you have added previously should be listed under "Use existing repository location". Select it.

  4. Choose a name for the new folder that will be created in your repository.

  5. At this point you should be able to browse to your repository using the "SVN Repository Perspective" and see that the new project has been added. Cool! Welcome to version control.

2.3. svn checkout: Retrieving Projects from Your Repository

Now you’ve figured out how to add things to your repository. But how do you retrieve stuff that is already there?

Subversion refers to this process as a checkout. To checkout a project in Eclipse, follow the following instructions:

  1. Start by opening the Eclipse SVN Repository Perspective. (Refer to the instructions above if you’ve forgotten how to do that.)

  2. Next we need to find the project that we want to open using the repository browser. Once you’ve located it, right click on it and select "Checkout".

  3. Select "Check out as a project in the workspace". Subversion uses HEAD to refer to the latest version of a project, so you should check out that version unless you want an earlier one for some reason.

  4. Click "Finish". The project should now appear in your workspace.

2.4. svn commit: Committing Changes to Your Repository

in case of fire 1 git commit 2 git push 3 leave building2

Remember: version control systems only save the change you have made when you tell them to. This is called a commit, and the process called committing. Given that committing is essentially saving your changes, this have given rise to memes like the one on the right—although it refers to Git, another popular version control system.

Once you commit a version of a file, Subversion will remember its committed contents forever—even if you change or delete it. So you should get into the habit of committing early and often. Here are some good times to commit your code:

  • You just started a project—make sure to record it in its initial state!

  • You just finished writing a function—that way you can always get back to that version if you make changes later.

  • You just passed one test case—make sure that Subversion remembers what worked forever!

  • You are about to take a break or go to bed.

  • The MP deadline is in thirty minutes—or in five minutes!

Get in the habit now of committing your code regularly. Version control systems are very efficient at storing commits, and so the overhead of performing them is small. Better to have things saved than to want desperately to get back to a previous version or remember how you did something and not have it committed.

Note that most version control systems will require you to tell them the first time you want to add a new file to a project. Once you do this once, that file will be tracked in the future—but there is an initial step that you may sometimes miss.

Here’s how to generate a Subversion commit using Eclipse:

  1. You should have the Project Navigator view open—the typical view that you use when writing, testing, and debugging your code.

  2. Right click on the Eclipse project you want to commit and select "Team → Commit".

  3. Add a comment to your commit! Comments are really important to helping others—and you—understand what changed from this commit to the last one. Get in the habit of writing good ones 4.

  4. If your commit includes new files, select them or click "Select All" to add all new files at once.

  5. Click OK to finish your commit.

2.5. svn update: Retrieving Changes to Your Repository

Committing allows you to save your changes to the project in your repository. To retrieve updates made by others, you perform an update.

Subversion, like other version control systems, provides you with control over when you receive updates. This is another big advantage when compared with systems like Dropbox that propagate changes immediately. If you are working with others, you may not want to see their changes immediately—particularly if they might interfere with what you are working on. Having to update manually means that you get to choose a moment when you are ready to receive changes.

In CS 125 you are working on assignments independently—so you might ask, who else would be updating my repository? There are two possible answers to that question! First, we may use your Subversion repository to return grades and testing results to you. We do this by adding new files to your repository that you then retrieve the next time you update. It’s also possible that you may choose to work on two different machines—a laptop and a desktop at home. Assuming you have set up Eclipse and Subversion properly on both, you can use the update command on one machine to retrieve commits made on the other.

Here’s how you perform an update in Eclipse:

  1. Right click on the project that you want to update.

  2. Click "Team → Update HEAD". This will get you the latest changes.

At this point it is possible that the changes made by others have conflicted with yours. If this happens, Eclipse will mark the files in your project for you to fix.

2.6. Checking for Changes

Version control systems are designed to allow you to compare between your local files and the copies that are available in the repository. So you should never browse the contents of your remote repository to make sure that its contents are up-to-date. Not only is that tedious, but it doesn’t work well once your repository has even just a few files.

Instead, use Subversion to examine the differences between your local files and your remote repository. Here’s how:

  1. Right click on your project and open the "Compare With" menu.

  2. Choose "Latest from Repository"

  3. At this point, one of two things will happen. Either the Subversion plugin will tell you that there are no changes, or it will open up a view where you can examine the differences between the files in your repository.

3. How to Learn More

As usual the internet is the best way to find out more about anything related to technology. There are great Subversion tutorials out there that you can find on Google. Or ask a member of the course staff for help 5.

CS 125 is now CS 124

This site is no longer maintained, may contain incorrect information, and may not function properly.


Created 10/24/2021
Updated 10/24/2021
Commit a44ff35 // History // View
Built 10/24/2021 @ 21:29 EDT