Shelving in Subversion?

The person whom I report to asked me today whether there is a feature similar to shelving available in Subversion. The good news is that you can "shelve" in Subversion. The bad news is that it requires a bit of admin.

In Subversion, the concept of shelving is known as private branching. Here are the steps:

Step 1: Create a branch, switching your working copy

Let's say that you are working on the trunk and I have some modifications that I would like to shelve. The trunk url is http://localhost:81/svn/default/Trumpi.CruiseControl/trunk (this is a private repository on my home PC). To shelve my modifications, I create a branch in http://localhost:81/svn/default/Trumpi.CruiseControl/shelves/trumpi/my-feature. Be sure to switch to the new branch as well. Take note of the revision number!

 

Step 2: Commit the modifications to the shelf

Take note of the revision number here too!

Step 3: Restoring the modifications from the shelf

When you need to restore from the shelf, make sure that your working copy is pointing to the trunk url. Typically the trunk url will have no modifications, but if it does then that is not a problem. What you need to do is perform a merge.

When performing the merge, ensure that the "from" revision is the revision number mentioned in step 1. (You did remember it, right?) Likewise, make sure that the "to" revision is the revision number mentioned in step 2. Lastly, make sure that the "from" url and the "to" url is the url of the shelf. The diagram below shows an example.

Now you're probably thinking "Hey, that's not really that slick." I agree. It involves a lot of admin and is certainly an advanced use of Subversion. But at least we know that it is possible and I would like to see Subversion providing a shelf command in the future that abstracts the complexity of these steps away from us.

Published Wednesday, May 23, 2007 10:01 PM by trumpi
Filed under:

Comments

No Comments