Reverting to a previous CVS version

Ovid on 2007-06-04T13:59:24

There must be a simpler way of doing this. I accidentally committed some files in CVS which I shouldn't have. I needed to revert them to the previous version, but doing this for each file by hand would be tedious, so I wrote the following:

#!/usr/bin/perl

use strict;
use warnings;

my $file = shift or die "usage:  $0 filename";

unless ( -f $file ) {
    die "($file) does not appear to be a file";
}

my $log = qx{/usr/bin/cvs log $file};
my @versions = $log =~ m{
    \n-{28}\n
    revision\ (\d+\.\d+)\s*\n
    date:\ \d\d\d\d/\d\d/\d\d
}gx;

my ( $current, $previous ) = @versions[ 0, 1 ];
unless ( $current && $previous ) {
    die
      "Could not determine current ($current) or previous ($previous) versions";
}
`/usr/bin/cvs diff -r$current -r$previous $file | patch --unified`;

What's the easy/correct way to do this?


cvs diff -D

IlyaM on 2007-06-04T14:15:23

If I recall correctly use can use -D to select relevant diff by date range.

Use the tags, Luke

stephenca on 2007-06-05T10:50:32

It's too late for this now, but good practice is to tag your files before and after a commit. That way you can use the -j ("join") option to update to revert:

cvs update -j after_change -j before_change filename.pl

(then commit and tag again, obviously).

You can still do this in your code sample (using the after- and before revision numbers, rather than tags), which would eliminate the pipe to patch.