Wednesday, January 28, 2009

Restore a deleted file from subversion.

If you want to restore a deleted file from svn there are a few ways to do it, and some work better than others.

The subversion book gives the basic info for restoring a file using either merge or copy. However, the method used in the example for copy didn't work for me. So let's say you delete a file "" in revision 100. Then you would want to restore the file, using the previous revision, into the current working directory like this.

svn copy -r 99

My svn server didn't seem to handle the revision option correctly, and kept telling me that the file didn't exist. So an alternative syntax looks like this:

svn copy

This second syntax, which I didn't see mentioned in the svn book, worked like a charm for me.

If you don't know in which revision the file was deleted, you can use svn log in the directory to see a history of file changes.

After you copy the deleted file, you are not quite finished. You'll still have to commit your changes. So something like svn commit -m "Restore file" will finish the job.

No comments: