History: Confronting your Past


Each of the various files inside that folder has its own version number, but every time one of those files changes, the version number of the folder is increased by one as well.  So the version number of a folder is a little bit like a label because it maps to a specific snapshot of the contents of the folder.

However, CVS doesn't work this way.  There is no folder version number which can be mapped to a specific snapshot of the contents of that folder.  For this reason, tags are all the more important in CVS, since there is no other way to easily mark specific versions of multiple items as a snapshot.

When to Use a Label
Labels are cheap.  They don't consume a lot of resources.  Your SCM tool won't slow down if you use lots of them.  Having more labels does not increase your responsibilities.  So you can use them as often as you like.  The following situations are examples of when you might want to use a label:

When you make a release

A release is the most obvious time to apply a label.  When you release a version of your application to customers, it can be very important to later know exactly which version of the code was released.

When something is about to change

Sometimes it is necessary to make a change which is widespread or fundamental.  Before destabilizing your code, you may want to apply a label so you can easily find the version just before things started getting messed up.

When you do an automated build

Some automated build systems apply a label every time a build is done.  The usual approach is to first apply the label and then do a "get by label" operation to retrieve the code to be used for the build.  Using one of these tools can result in an awful lot of labels, but I still like the idea.  It eliminates the guesswork of trying to figure out exactly which code was in the build.

When you move some changes from one place to another

Labels are handy ways to mark the sync points between two branches or two copies of the same tree.  For example, suppose your company has two groups with separate source control systems.  Group A has a library called SuperDuperNeatoUtilityLib.  Group B uses this library as well, but they keep their own copy in the their own source control repository.  Every so often, they login into Group A's repository and see if there are any bug fixes they want to migrate into their own copy.  By applying a label to Group A's repository, they can more easily remember the latest point at which their two versions were in sync.

Best Practice: Use Labels Often
Labels are very lightweight. Don't hesitate to use them as often as you want. Once you have a label, the question is what you can do with it.  The truth is that some labels never get used.  That's okay.  Like I said, they're cheap.

But many labels do get used.  The "get by label" operation is the most common way that a label comes in handy.  By specifying a label as the version you want to retrieve, you can get a copy of every file exactly as it was when the label was created.

It's also very handy to diff against a label.  For example, in the following screendump from Vault, I am asking to see all the differences between the contents of my working folder and the contents of the label named "Build"  (This label

About the author

AgileConnection is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.