SVN is not always intuitive and its errors are often even less so. Such was my experience when I tried to restore a file that have been accidentally deleted many revisions ago. The normal process spoken of is to simply copy the file from the old revision into the current revisions. The first step is to find the file:

svn log --verbose

Then scan for the file revision where the file was removed. Let’s say the file was canfield.conf, we look for the D operation on canfield.conf in the log, then we know the prior version contains the file we want. In the example below (... indicates other log entries) the revision I deleted the file was ‘99’, so revision ‘98’ contains the latest version of the file before I removed it.

------------------------------------------------------------------------
r100 | robb | 2009-04-13 11:46:44 -0700 (Mon, 13 Apr 2009) | 2 lines
Changed paths:
   A /trunk/packages/foobar.conf
foobar package configuration file
------------------------------------------------------------------------
r99 | robb | 2009-04-13 11:40:05 -0700 (Mon, 13 Apr 2009) | 2 lines
Changed paths:
  ...
   D /trunk/packages/canfield.conf
  ...
Cleanup
------------------------------------------------------------------------
r98 | robb| 2009-03-02 22:48:58 -0800 (Mon, 02 Mar 2009) | 2 lines
Changed paths:
  ...

It should be simple to restore the file, but alas it is a bit complicated. The following do not work as I expected:

svn update -r 98 canfield.conf

That restored the file BUT it is not in the current revision set, so on an svn update it will vanish. Not overly useful. Let’s try the copy command which is often listed as the way to recover a file, for this we need the repository address. If you cannot remember the repository URL simply look in .svn/entries it will be the first URL listed. I have masked the URL with {URL}

svn copy -r 98 https://{URL}/canfield.conf .

This fails with a strange error:

svn: '/svn/crg/!svn/bc/102/trunk/canfield.conf' path not found

Apparently, since there is no canfield.conf in the current revision it cannot copy to it?!? I admit that this doesn’t make any sense to me at all but I am sure SVN gurus will find it obvious. After some research I found an additional option for the URL; the @{revision}. Let’s try using that:

svn copy -r 98 https://{URL}/canfield.conf@98 .

And it works! Don;t forget to save this file, the above just copied it into our working area, it did not commit the file to the repository yet.

svn commit

So if you see a weird /bc/ error from SVN try appending @{revision} to the URL and see if that helps. See also the Peg and Operative Revisions in the SVN Manual.

I really need to start playing with GIT....