You are here

Using CVS to Get an Older Version of a File

Printer-friendly versionPrinter-friendly version
Getting the older version of the file is simple, but it is a little tricky to then use the old version as a starting point for new edits.

CVS "tags" the file with the version number. This tag can get in the way of either committing the old version with new edits or going back to the most up to date version.

To decide which old version of the file you want - look at the cvs log entries:

        % cvs log oldfile
        < figure out which revision you want from the log >
	(Note: This is why it's a good reason to log your edits at commit time, as CVS invites you to!)
	

Differences Between Versions

To see exactly what has changed between two different revisions of a file:
	cvs diff -r < first version > -r < second version >  oldfile
	

Making the Old Version the Current Version

To revert to older version of a file, do:
	cvs update -j 1.7 -j 1.5 oldfile
	
You can then edit and commit oldfile as usual.

Problems with Updating Old Versions - the "sticky tag"

If you update a file without the "-j option" - for example:
        % cvs update -r 1.5 oldfile
	

... you may find that you can't then make changes and commit the file. The file's "status" will indicate that it now has a sticky tag.

        % cvs status oldfile 
	===================================================================
	File: oldfile	Status: Locally Modified

   	Working revision:    1.5
   	Repository revision: 1.5     /cvsroot/examples/oldfile,v
   	Sticky Tag:          1.5
   	Sticky Date:         (none)
   	Sticky Options:      (none)
        ===================================================================

	

If you now edit this file and try to commit the edits (ie commit version 1.6), the commit will fail.
CVS will complain about the sticky tag. More pernicious, CVS will not update the file with a normal "cvs update" command because it will look at the sticky tag and assume you want the file to be at version 1.5.

Getting Rid of the Old Version

If you want to go back to the most up to date version just do the following:
         % cvs update -A oldfile 

The -A tag tells update to get rid of the sticky tag and do a full update of the file.

Making the Old Version the Current Version

Save the version of "oldfile" to something else and check out the "current" version.
Note: you must still to do update -A to get the current version, because even though you have renamed "oldfile" the tag is still associated with the file "oldfile" and is not removed till update -A is done.
Then rename the "old" version to the "current" version.

         % mv oldfile oldfile.old.ver
         % cvs update -A oldfile
         % mv oldfile.old.ver oldfile
         % cvs commit -m "reverting to version 1.5" oldfile

You can now carry on checking out, editing and committing the file as normal.

Last reviewed: 
24/02/2013

System Status

Home dirs (AFS)
Network
Mail
Other services
Scheduled downtime

Choose a topic