Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Monday June 04, 2007
08:59 AM

Reverting to a previous CVS version

[ #33421 ]

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:


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{
    revision\ (\d+\.\d+)\s*\n
    date:\ \d\d\d\d/\d\d/\d\d

my ( $current, $previous ) = @versions[ 0, 1 ];
unless ( $current && $previous ) {
      "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?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • If I recall correctly use can use -D to select relevant diff by date range.

    Ilya Martynov ( [])

  • 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

    (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.