Subversion Insider Tips
So, you’ve got to grips with using Subversion in your day-to-day development; you’ve read up on best practices, and even branching and merging is no longer giving you nightmares – but are you taking full advantage of everything Subversion has to offer? In this post, we look at some useful, but frequently overlooked, Subversion features.
Revert Command
The Subversion repository remembers every change that’s made to the files and directories, which is useful when reviewing the history of changes made within your project, but it also allows users to recover older versions of their code.
The ‘svn revert’ command can be used to overwrite any local changes made to the working copy, with the code held in the repository. This includes any property changes, and any scheduling operations that may have been set on the working copy. Note that the revert command replaces all changes made to your working copy – once they are gone, there is no way to recover them; you will lose all the changes made since the last commit.
Reverse Merge
A reverse merge rolls back a change that has already been committed to the repository, and then applies it to the local working copy. A reverse merge can be performed with the following commands:
1) svn merge –dry-run – (optional) displays what the merge will produce.
2) svn merge -r (revision number) – rolls the working copy back to the specified revision. Note that a reverse merge is like any other merge operation, so ‘svn status’ and ‘svn diff’ can be used to inspect and approve the changes.
3) svn commit – the merge command will only change files in the working copy, so remember to commit the changes to the repository.
External Files and Folders
Occasionally, it’s useful to construct a working copy that consists of several different checkouts. To help with this, Subversion supports external definitions, which allow users to map a local directory to the URL of a versioned resource. External definitions are declared with the ‘svn:externals’ property.
Once ‘svn externals’ is set on a versioned directory, everyone who checks out a working copy from that directory, also checks out the definitions, so only one person needs to define the nested working copy checkout per repository.
To edit the externals definition, use the following subcommand:
svn propedit (target)
When anyone runs ‘svn update,’ Subversion will automatically synchronize the checked out items against the changed externals definition. Similarly, when other team members update their working copy, they will automatically receive any changes made to the externals definition.
The ‘svn status’ command can be used to print the status of working copies and directories with ‘svn:externals’ properties, as ‘svn status’ recognizes externals definitions.