tags:

views:

4366

answers:

5

I've removed a checked in file from the CVS branch, i.e.:

cvs remove -f file.txt
cvs commit

How do I restore the file?

+10  A: 

I believe that:

cvs add file.txt
cvs commit file.txt

... will resurrect it from the attic.

Jason Etheridge
A: 

I get this error when I try to restore file.txt using cvs add and commit:

$ cvs add file.txt
cvs server: re-adding file file.txt (in place of dead revision 1.2)
cvs server: use 'cvs commit' to add this file permanently

$ cvs commit file.txt
cvs commit: warning: new-born file.txt has disappeared
cvs server: Up-to-date check failed for `file.txt'
cvs [server aborted]: correct above errors first!
Harry
Try a "cvs update" in the directory containing file.txt; or "cvs update file.txt". (I ran through your scenario to confirm the solution works, so it should work! :-)
Jason Etheridge
According to http://ximbiot.com/cvs/wiki/CVS%20FAQ (search for "How do I undelete a file?") cvs add file.txt should do the trick. Have you created a file.txt in the directory before you try the add (don't think you should)
Oskar
+1  A: 

I've found that you can not use cvs add to undo a cvs remove operation that has already been comitted. So this works:

$ cvs remove -f file.txt
$ cvs add file.txt

but this doesn't work:

$ cvs remove -f file.txt
$ cvs commit
$ cvs add file.txt


The simplest method I've found so far is to run cvs status file.txt to find out the revision number. Then grab the contents of the revision and add it back in:

$ cvs update -p -r rev file.txt > file.txt
$ cvs add file.txt
$ cvs commit
Harry
+1  A: 

Given Harry's lack of success, here's a transcript of what I did to demonstrate that the above answer works (apologies in advance for its length):

C:\foo>dir
 Volume in drive C is Local Disk
 Volume Serial Number is 344F-1517

 Directory of C:\foo

28/09/2008  05:12 PM    <DIR>          .
28/09/2008  05:12 PM    <DIR>          ..
28/09/2008  05:12 PM    <DIR>          CVS
28/09/2008  05:11 PM                19 file.txt
               1 File(s)             19 bytes
               3 Dir(s)  22,686,416,896 bytes free

C:\foo>cvs status file.txt
===================================================================
File: file.txt          Status: Up-to-date

   Working revision:    1.2     Sun Sep 28 07:11:58 2008
   Repository revision: 1.2     C:\jason\CVSROOT/foo/file.txt,v
   Sticky Tag:          (none)
   Sticky Date:         (none)
   Sticky Options:      (none)


C:\foo>cvs rm -f file.txt
cvs remove: scheduling `file.txt' for removal
cvs remove: use 'cvs commit' to remove this file permanently

C:\foo>cvs commit -m "" file.txt
Removing file.txt;
C:\jason\CVSROOT/foo/file.txt,v  <--  file.txt
new revision: delete; previous revision: 1.2
done

C:\foo>cvs status file.txt
===================================================================
File: no file file.txt          Status: Up-to-date

   Working revision:    No entry for file.txt
   Repository revision: 1.3     C:\jason\CVSROOT/foo/Attic/file.txt,v

C:\foo>more file.txt
Cannot access file C:\foo\file.txt

C:\foo>dir
 Volume in drive C is Local Disk
 Volume Serial Number is 344F-1517

 Directory of C:\foo

28/09/2008  05:12 PM    <DIR>          .
28/09/2008  05:12 PM    <DIR>          ..
28/09/2008  05:12 PM    <DIR>          CVS
               0 File(s)              0 bytes
               3 Dir(s)  22,686,400,512 bytes free

C:\foo>cvs add file.txt
cvs add: Resurrecting file `file.txt' from revision 1.2.
U file.txt
cvs add: Re-adding file `file.txt' (in place of dead revision 1.3).
cvs add: use 'cvs commit' to add this file permanently

C:\foo>cvs commit -m "" file.txt
Checking in file.txt;
C:\jason\CVSROOT/foo/file.txt,v  <--  file.txt
new revision: 1.4; previous revision: 1.3
done

C:\foo>more file.txt
This is a test...

C:\jason\work\dev1\nrta\foo>dir
 Volume in drive C is Local Disk
 Volume Serial Number is 344F-1517

 Directory of C:\jason\foo

28/09/2008  05:15 PM    <DIR>          .
28/09/2008  05:15 PM    <DIR>          ..
28/09/2008  05:13 PM    <DIR>          CVS
28/09/2008  05:13 PM                19 file.txt
               1 File(s)             19 bytes
               3 Dir(s)  22,686,375,936 bytes free

Clearly he's doing the right thing, but the behaviour he's observing is different. Perhaps there's a difference due to CVS version (I'm using 1.11.22 on Windows).

Jason Etheridge
Thanks Jason for taking your time to provide a detailed response.
Harry
+1  A: 

The cvs add did not work for me because my cvs version on the server was very old. I have confirmed that it works fine with CVS version 1.11.22.

Harry
I'm glad we got to the bottom of that, Harry. I was getting a little concerned. :-)
Jason Etheridge