dark

Recovering a deleted file in Subversion

blank

Many times I have been looking on the Internet to find a suitable solution for this, but in the end I’ve created my own solution.

These next steps will explain how to recover a deleted file back into the HEAD revision, in a Subversion repositry.


The following example shows how to Subversion commands should be executed.

  • At first, a test environment is created:
    .oO( ~/trunk )Oo. svn mkdir test_dir
    A         test_dir
    .oO( ~/trunk )Oo. ls
    test_dir
    
    .oO( ~/trunk )Oo. cd test_dir/
    .oO( ~/trunk/test_dir )Oo. ls
    .oO( ~/trunk/test_dir )Oo. echo 'Regel 1'  >>file_1
    .oO( ~/trunk/test_dir )Oo. svn add file_1
    A         file_1
    .oO( ~/trunk/test_dir )Oo. svn ci -m '-m test set up'
    Adding         test_dir
    Adding         test_dir/file_1
    Transmitting file data .
    
    Committed revision 14.
    
    .oO( ~/trunk/test_dir )Oo. ls
    file_1
  • Next, a certain file will be deleted:
    .oO( ~/trunk/test_dir )Oo. svn delete file_1
    D         file_1
    .oO( ~/trunk/test_dir )Oo. svn ci -m '- deleting test file'
    Deleting       test_dir/file_1
    
    Committed revision 15.
  • Afterwards, a few more Subversion commands are executed to have some more logging and revision numbers:
    .oO( ~/trunk/test_dir )Oo. echo 'Regel 1' >file_2
    .oO( ~/trunk/test_dir )Oo. svn add file_2
    A         file_2
    .oO( ~/trunk/test_dir )Oo. svn ci -m '- added second test file'
    Adding         test_dir/file_2
    Transmitting file data .
    
    Committed revision 16.
  • The svn log --verbose command shows which the commit messages, revision numbers and affected path names:
    .oO( ~/trunk/test_dir )Oo. svn log --verbose
    ------------------------------------------------------------------------
    r16 | jmorano | 2010-08-31 15:47:21 +0200 (Tue, 31 Aug 2010) | 1 line
    Changed paths:
    A /trunk/test_dir/file_2
    
    - added second test file
    ------------------------------------------------------------------------
    r15 | jmorano | 2010-08-31 15:46:53 +0200 (Tue, 31 Aug 2010) | 1 line
    Changed paths:
    D /trunk/test_dir/file_1
    
    - deleting test file
    ------------------------------------------------------------------------
    r14 | jmorano | 2010-08-31 15:45:52 +0200 (Tue, 31 Aug 2010) | 1 line
    Changed paths:
    A /trunk/test_dir
    A /trunk/test_dir/file_1
    
    -m test set up
  • Since in revision r15 the file file_1 was deleted, one revision less will be used to recover the file, using the svn update -r command. Beware that the file must be first renamed to a new filename and afterwards renamed to the original filename!
    .oO( ~/trunk/test_dir )Oo. svn update -r14 file_1
    A    file_1
    Updated to revision 14.
    .oO( ~/trunk/test_dir )Oo. svn rename file_1 new_file_1
    A         new_file_1
    D         file_1
    .oO( ~/trunk/test_dir )Oo. svn status
    D      file_1
    A  +   new_file_1
    .oO( ~/trunk/test_dir )Oo. svn ci -m '- readding'
    Deleting       test_dir/file_1
    Adding         test_dir/new_file_1
    
    Committed revision 17.
  • Check the Subversion logging:
    .oO( ~/trunk/test_dir )Oo. svn log new_file_1
    ------------------------------------------------------------------------
    r17 | jmorano | 2010-08-31 15:53:46 +0200 (Tue, 31 Aug 2010) | 1 line
    
    - readding
    ------------------------------------------------------------------------
    r14 | jmorano | 2010-08-31 15:45:52 +0200 (Tue, 31 Aug 2010) | 1 line
    
    -m test set up
    ------------------------------------------------------------------------
  • Rename the new filename to the original filename:
    .oO( ~/trunk/test_dir )Oo. svn rename new_file_1 file_1
    A         file_1
    D         new_file_1
    .oO( ~/trunk/test_dir )Oo. svn ci -m '- readding'
    Adding         test_dir/file_1
    Deleting       test_dir/new_file_1
    
    Committed revision 18.
  • Check the Subversion logging:
    .oO( ~/trunk/test_dir )Oo. svn log --verbose file_1
    ------------------------------------------------------------------------
    r18 | jmorano | 2010-08-31 15:54:09 +0200 (Tue, 31 Aug 2010) | 1 line
    Changed paths:
    A /trunk/test_dir/file_1 (from /trunk/test_dir/new_file_1:17)
    D /trunk/test_dir/new_file_1
    
    - readding
    ------------------------------------------------------------------------
    r17 | jmorano | 2010-08-31 15:53:46 +0200 (Tue, 31 Aug 2010) | 1 line
    Changed paths:
    A /trunk/test_dir/new_file_1 (from /trunk/test_dir/file_1:14)
    
    - readding
    ------------------------------------------------------------------------
    r14 | jmorano | 2010-08-31 15:45:52 +0200 (Tue, 31 Aug 2010) | 1 line
    Changed paths:
    A /trunk/test_dir
    A /trunk/test_dir/file_1
    
    -m test set up
    ------------------------------------------------------------------------
  • Previous Post

    Updating Darwin ports on Mac OS X

    Next Post

    Hacking the easy-fancybox WordPress plugin

    Related Posts