5 Tips for Learning Version Control with Subversion

Have you tried working with Subversion, the tool that saves a history of all revisions of your files? Version control with Subversion enables you to track and manage all the changes in your files, compare different revisions, revert to previous versions, and collaborate with other users while catching and managing any conflicts that may occur.

This post aims to provide some tips for new users on doing version control with Subversion. These tips are general in nature, but also contain some instructions specific to TortoiseSVN.

1. Revert your files

Subversion is designed to ensure that you don’t lose the changes you make to a file. But what if you DO want to undo those changes? The ‘revert’ command in Subversion that will do exactly. To revert means discarding all changes or modifications that are made to files that are not committed yet, are restore it back to the last known state.

Subversion ensures that you usually delete the right file by asking you with a prompt. If you happen to select the wrong file to revert and accidentally clicked “yes” to the prompt, you can still retrieve the file. TortoiseSVN does not just revert your files, it also moves the file to the Windows recycle bin. So you can find your files in the recycle bin and simply restore them.

Note that using the recycle bin is optional. You can disable the use of recycle bin when reverting by unchecking the option “Use recycle bin when reverting” in the settings dialog of your Subversion.

2. Move and Rename your files

When doing version control with Subversion, you can move and rename versioned files inside a working copy. If you want to rename a file or folder in place, use the Context Menu, then click Rename. You must enter a new name for the file and you’re done.

If you want to move files around inside your local copy, perhaps into a subfolder, select the files or directories you want to move. Drag them into the new location inside the local copy using the right mouse button. Release the right mouse button. In the popup menu, select Context Menu then choose SVN Move versioned files here.

Important: if you move or rename files without using proper Subversion commands it can lead to errors. For example, if you rename a file named file1.txt to file2.txt without using the Subversion command, file1.txt will appear as missing, while file2.txt will show up as “non versioned” in the commit dialog (Check for Modifications dialog).

You can still correct your files by going to the Check for Modifications dialog or commit dialog. Then you must select the files (Ctrl-click), right click, and choose “Repair move” from the context menu. The “Repair move” command will only work if two files are selected— one “missing” file, and another “non versioned” file. This is the only that way can Subversion find out which file was renamed. By executing the command, Subversion repeats the renaming of the file.

3. Visualise the revision graph as a .svg file

The revision graph shows you a quick overview of your project. However, you cannot share your graph to other people unless you save it as an image. If your graph is small, you can simply save it as .png file. You can also save the graph as .wmf file but note that .wmf files can only open in Windows.

If you are using TortoiseSVN 1.7 or newer, the revision graph can also be saved as a .svg file. A .svg file stores the image in a vectored format and hence it can be resized without affecting its resolution, unlike a .png file that is pixilated when enlarged. It can also be viewed in all modern browsers.

4. Export to remove hidden .svn folders

When zipping or archiving files, you may want to remove the hidden .svn folders inside your Subversion working copy. To do that, you can export in Subversion. Exporting a working copy will create a copy of the files without the unwanted .svn folders, however Subversion can no longer track changes in the exported copy.

Right-click on a working copy and choose “Export” from the context menu. A browse dialog of folders is shown where you can choose the folder where you want the new working copy to be exported to. If you select the same path of your working copy (that is, you are exporting a working copy onto itself), then Subversion will remove all hidden .svn folders of that local copy.

5. Organize files with right drag

It is possible for you to move or copy your files not only with the left mouse button, but also with the right mouse button. What is the difference between the two? Left drag does the command immediately, but the right drag will first show a menu where you can choose the operation.

Subversion provides additional commands in the right drag context menu. When you drag unversioned files using the right mouse button, you will be given a context menu that will enable you to add the files/folders to the working copy. An entry “Apply patch” will also show up if you drag a *.patch or *.diff file onto a working copy. This command opens up Subversion Merge allowing you to apply the patchfile to that working copy location.

Also, if you right drag a file into the location where the file already exists, SVN will ask you if you will rename the file, overwrite it, or cancel the move. Hence, right drag is useful when you simply want to export your working copy to another folder, as well as when you want to reorganize your files by copying and moving them around.

These five beginning tips for version control with Subversion should help you get started today. Make sure to come back for more Subversion tips in the future!

Version Control

Leave a Reply