I've just read up on how to undelete files in the Subversion revision control system. It's quite elegent, because of the way Subversion treats revisions and copying, but it's not obvious. Here's the short version, mainly for my own notes. See the the Subversion book for a more detailed treatment.
I'm assuming you've recently done svn rm on a file (or
directory) and then committed it. First have a look at the logs to find
out what revision the file last existed in:
$ svn --verbose log r1609 | fred | 2004-06-28 11:51:27 +0100 (Mon, 28 Jun 2004) | 1 line Changed paths: D /trunk/foobar no longer necessary. ------------------------------------------------------------------------ ...
In this case, revision 1609 removed the file foobar, so the most recent version of that file resides in revision 1608. Once you have this number, you simply copy the file from the past into the present (i.e., your working copy) like so:
$ svn copy --revision 1608 file:///.../trunk/foobar foobar
Then commit that new file. This way of doing things has nice features:
- You can copy the original file from any previous revision, so as well as simply undeleting a file when you removed the wrong one, you can revert a file to the version you had 6 months ago, or whatever.
- The
svn copycommand keeps track of the origin of the file, so if you look at the verbose logs (do asvn updatefirst to make sure you get the latest logs) you can see that the version of foobar in the latest revision came from a file of the same name in a particular older revision.
Having said that, it would be nice to have a simple
svn undelete command. It should just do the
copy operation, but automatically work out the most recent revision
it could copy from. That would make the common case a lot more
convenient.