CVS magic - bringing files back to life

Posted on June 4, 2004

So the time comes when you want to get a file back from the dead. You’ve deleted it in the past because you were positive you wouldn’t need it but, lo and behold, you need it again now.

That’s OK, you just go into the repository and move the file from the Attic back to the “live” directory and you’re done, right?
Not quite…

Actually when you “cvs remove” a file CVS not only moves it into the Attic but also makes a new revision of the file and marks it as “dead”.

Here is how it might look:

head    1.10;
locks; strict;
comment @# @;

date    2004.;    author admin;   state dead;
next    1.9;

date    2003.;    author admin;   state Exp;
next    1.8;

... ... ...

So you see that the file was in version 1.9 and then it was removed and gained a new version (1.10) and is now dead (state dead;).

OK, now what?

Well, here’s how you go about bringing the file back into working shape:

  1. Go into the working copy of the project

     cd ~/my_project 
  2. Issue the following command to recover the file

     cvs -Q update -p -r 1.9 >
  3. Add the file (again)

     cvs add
  4. Commit it cvs ci -m “back from the dead”

And you’re done.

The thing that still bugs me is that you have to delve into the repository to find out the last revision the file had before deletion but so far I couldn’t find a better way to do it.

Kudos to Melo who is always surrounded by nice books like the one this tip came from - Open Source Development with CVS.