Thursday, May 29, 2008

Recover a deleted file in Subversion

May 29th, 2008 By: brian
SVN is great for keeping our projects under tight control. Occasionally, we have the need to get something back that was deleted in a previous revision. So I can remember how to do it next time, here it is:
$ svn copy -r 1234 url/to/deleted/file path/to/recovered/file
This will copy the file at the revision specified to the new file in the “restore to path” part. You can find the revision by doing an ’svn log –verbose’ of the directory it was in. That’s all there is to it!
My theme seems to be restoring and recovering… is that a bad thing?

6 Responses to “Recover a deleted file in Subversion”

  1. Tarun Says:
    If you are giving the repository url, the -r or –revision parameter doesnt work.
    instead specify the old revision by appending @revision-number to end of the old file url.
    svn copy svn://repo-path/file-path@old-revision-number relative-path-to-new-location
    example -
    cd working-copy/mydir
    svn copy svn:// .
    will copy the the file ‘myfile’ from revision 21 into the current directory.
  2. Clifton Says:
    Your forgot a hyphen in the svn log command:
    svn log –verbose
  3. Frank Says:
    I was not able to use the @revision syntax, but -r worked just fine.
    The following command restored a deleted README file (with log entries back to 1993!) in my current working directory:
    svn copy -r http:////README .
    – Thanks for the help!
  4. Frank Says:
    Sorry, but that last post got scrambled; blame it on careless use of angle brackets.
    Hopefully, this version of the command will come through unscathed:
    svn copy -rrevision_number_where_deletedhttp://svn_machine_name/svn_repository_path/README .
  5. Shiv Says:
    Do you happen to know if there’s a difference between doing it the way you proposed versus using TortoiseSVN right-click feature as mentioned here?
    I tried the TSVN way, and it seemed to work for me. That is, all of the log history is still retained.

No comments:

Post a Comment