Monday, November 28, 2011

Recovering deleted files from an svn repository

Hi

This posts show how to recover a deleted file in Subversion.
Assuming the file is called "VeryImportantFile.java" and it was deleted by mistake by the sloppy developer John Doe.

1. Get svn log
Assuming the file is to big to work with in the terminal we save the output
>svn log --verbose > svn_log_verbose

2. Open file in text editor
>gedit svn_log_verbose

3. Find the commit that delete it
Ctrl+F "VeryImportantFile.java"

Fixed stuff in the system
------------------------------------------------------------------------
r53308 | john_doe | 2011-11-17 13:15:39 +0100 (Thu, 17 Nov 2011) | 1 line
Changed paths:
M /trunk/xmlapi-test/src/test/java/com/RegularFile.java
A /trunk/xmlapi-test/src/test/java/com/NewFreshFile.java
D /trunk/xmlapi-test/src/test/java/com/VeryImportantFile.java

4. Revert it
You need to use one revision BELOW the one that deleted it.
> svn up -r 53307 src/test/java/com/VeryImportatFile.java
A src/test/java/com/VeryImportantFile.java
Updated to revision 53307.

5. Add to repo
> svn cp -r 53307 src/test/java/com/VeryImportantFile.java svn://svn.project.com/java/trunk/xmlapi-test/src/test/java/com/VeryImportantFile.java
Now you are promted default text editor to enter commit message. Enter message, save file and Exit to commit.
( cp is short for copy )

6. Update Repo
> svn up
U src/test/java/com/VeryImportantFile.java
Updated to revision 53790.

Now the file is reverted and back in repo! Life could not be better!