Restoring Files From Subversion (or: Subversion is Retarded)
One of the great things about a version control system is that you can resurrect deleted files and revert changes. This is a fairly common task - well, not excessively common, but it definitely happens.
In this case, I want to resurrect a directory that, even though I reverted the delete, Subversion decided to commit anyway. (Apparently "svn revert" doesn't actually revert changes like deleting the file. It copies it back, and then deletes it on commit anyway. svn status offers no indication this is the case.)
So how do you resurrect a dead file? (And the term is "resurrect," not "restore" - looking up "restore" won't find you a damned thing, you must "resurrect" it.)
Well, you have two strategies. Merge the old version in with the new copy (see
svn merge) or copy the old version to the working copy (see
svn copy). Notice how neither of these commands really has anything to do with restoring or resurrecting.
Let's say you want to undelete "file.txt" in your current repository because an unfortunately
svn delete command got it when it wasn't supposed to. How do you do this?
First, check the log. There's no way to pull up the log of the file you deleted, because it doesn't exist any more (?!). Instead you have to pull up the log of the directory it's in. And you'll want to use
-v to get a verbose listing of what was added and deleted so you can find what revision number the file was deleted in.
You'd think this would be the kind of thing that a command line utility could help you with, but as the general thrust of this post is that Subversion is retarded, it doesn't offer anything to help.
So once you've scanned through the revisions and found the revision number where the file was deleted, you're ready to copy it back in. You'll want to copy the revision prior to the revision it was deleted in, so after quickly decrementing the revision number, you're finally ready to start the copy command.
Well, not really. Before you can do that, it's a quick
svn info to find out what the URL is of the current directory. With that, you can write the copy command.
So the final command will be:
svn copy -r [revision] [url] [filename]
Let's assume that "file.txt" was deleted in revision 412, and
svn info gives us the URL of "http://svn.scm.example.com/repository/trunk/doc/text" for the directory containing "file.txt". The final command will be:
svn copy -r 411 http://svn.scm.example.com/repository/trunk/doc/text/file.txt file.txt
Heaven help you if the file you're trying to revert has a space in its name.
 Actually, you can. It involves knowing the full URL, which is a huge and unnecessary pain. Subversion already knows the URL, but is retarded and instead forces you to find it (via
svn info), copy it, and use the full path. Under Windows this can be even more painful if the URL is larger than a single line since Windows only copies blocks out of the console and not lines. So you get to copy multiple lines of the URL out.