How to recover “lost” changes in CVS

Suppose someone destroyed one of your file revisions by checking in a file undoing any changes you made. While your version is still in the CVS tree (you are using version control, aren’t you?), you don’t know how to merge them with the current version of the file.

Well, here’s a hack that will do it:


cvs update myfile
cvs update -r 1.39 -p myfile > mychanges
cvs update -r 1.38 -p myfile > beforemychanges
merge myfile beforemychanges mychanges

I’m sure there is a cleaner way to do it.

Published by

Daniel Lemire

A computer science professor at the Université du Québec (TELUQ).

3 thoughts on “How to recover “lost” changes in CVS”

  1. I seem to remember that you can also do it by using cvs update -j, which is used for merging. Reverting a checkin is basically like a backwards merge.

  2. Better late than never. Is that still true?

    For the record, if you use the double -j method, you need to put the revision numbers in the other order. To reverse the changes made by revision 1.39:

    cvs update -j 1.39 -j 1.38 myfile

    This usage computes the diffs needed to turn the first revision number into the second. If your objective is to turn the later revision back into the earlier one (i.e., to roll back the commit), then the later revision number has to come first.

    But is that what you intended, Daniel? Or is the merge step of the three files intended to restore the changes made in -r1.38 without clobbering other changes made in -r1.39? If so, then I don’t know of a better way to do it than the one you noted.

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax