Rolling Back to Old Versions of Files in CVS

Nov 24 2004

We use CVS on many of our projects. CVS allows several developers to collaborate on the same file, tracking their changes and merging them. At RD2, we use a program on our Windows machines called Tortoise CVS to interface with the CVS server. Tortoise CVS provides a friendlier interface to using CVS than using the command line (unless that floats your boat!).

Last week, in the course of developing a page for one of our clients, I determined that the route I was taking (and the changes I had “committed” to the CVS server) was not the direction I wanted to go, and needed to roll back to a previous version of the file. That’s one of the neat things about CVS — each time a developer “commits” their changes, a new version number is created. At any time, you can see what has changed between versions. In this case, I was up to version 1.10, but wanted to revert to version 1.08.

This is when things got tricky.

Thinking that it would roll back the version for all users, I right-clicked the file I was working on in my Explorer window and selected the CVS History. CVS History shows a log of all the versions of the file, who committed it to the CVS server, when it was committed, and any commentary provided by the person who committed the file. In the CVS History menu, I right-clicked on the version I wanted to roll back to (1.08) and selected “Get this revision (sticky)” thinking that meant every user would now see 1.08 as their version next time they “updated” their files. I was wrong.

“Get this revision (sticky)” acquires the file for only the user that selects it. “Sticky” also locks the file for that user (in this case, me!), not allowing them to commit changes to the file. This is because the server is sitting at version 1.10 and changes can’t be made to versions from the past. I was trying to update 1.08, but changes to it were no longer allowed.

In searching for a solution for the dilemma I created for myself, I had some difficulty locating the exact answer I needed (hopefully Google will find this post and help the search results be better).

After a bit of research and some playing around, I learned that to get out of this mess, I needed to do an “Update Special”. From that menu, I selected “Get tag/branch/revision” and “HEAD” from the dropdown menu. This released the “Sticky” issue I had, because it grabbed the latest version (1.10) and replaced the 1.08 version I had acquired and locked down locally. Selecting “HEAD” may not always work, dependent on your particular CVS configuration and the structure you have set up with a project.

The next step, and what I should have done originally, is selecting “Save this revision as…” and overwriting the local copy of the file. From there, update and commit the file. In this example, the CVS server would then make the committed file version 1.11.

For more on CVS, check out Introduction to CVS, Getting Started with CVS, or CVS Overview.

Tags

7 Comments to “Rolling Back to Old Versions of Files in CVS”

  1. Also excellent: Dave Thomas and Andy Hunt’s

    By Jeremy Dunck on December 7th, 2004 at 4:20 pm
  2. “hopefully Google will find this post and help the search results be better”
    And that’s how I found this page. This makes more sense than the other pages I’ve found and is the only one that isn’t full of command-line mumbo jumbo. Unfortunately my version of CVS (1.3.6.1) doesn’t have “Save this version as” as a menu option.

    By Susanna on August 12th, 2005 at 10:01 am
  3. Time to look at Subversion, Chris. CVS is a little long in the tooth, and Subversion addresses a lot of the shortcomings that CVS has.

    By Jerry Brown on December 5th, 2005 at 8:48 pm
  4. Good news Jerry. We’ve been using Subversion for quite some time!

    By Graham on December 5th, 2005 at 10:22 pm
  5. Heya Graham, thanks for putting this information online, it was a great help!

    By Patrick on June 6th, 2007 at 8:40 am
  6. Many thanks, since I just experienced the same thing and got it back to work perfectly with your tips.
    Agreed that SVN is better than CVS but sometimes you just don’t have choice if someone in the company decided to use CVS (like me :) ).

    By hanofee on July 12th, 2007 at 1:50 am
  7. Very nice!
    Thanks for the post on this. Jerry is right, we should move to svn very soon because this is way too tedious and time consuming. :)
    Cheers,

    By Miguel on November 13th, 2007 at 2:25 pm

Leave a Reply