Undeleting files with Subversion

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 copy command keeps track of the origin of the file, so if you look at the verbose logs (do a svn update first 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.

< Will the Windows API be replaced by web applications? | Suggesting a filename for downloaded files >

Miniblog

(nuggets of inanity)

Tuesday Apr 24th 2007, 16:54 »
Just took the annual web design survey that AListApart do. I don't realy consider myself to be a web designer, but I have been doing a lot of HTML and CSS lately.
Monday Apr 23rd 2007, 18:23 »
Strange, there appears to be a bare-knuckle boxing match going on in the field outside my flat. Wish they wouldn't make so much noise about it.
Thursday Mar 1st 2007, 18:47 »
“In its written form, Hebrew has no vowels, making it the ideal language for texting.”
—Said in jest on some Radio 4 programme just now.

Archive: 2007 · 2006 · 2005 · 2004
Feed