Recovering files deleted from an SVN repository

This morning I find myself in need of a file that used to exist in an SVN project. The file was deleted several months ago and I don’t have a copy anywhere else. Finding it in my SVN repository turned out to be quite simple.

Run the following command to dump the complete activity log from the project.
> svn log –verbose > myLog.txt

Then simply open the ‘myLog.txt’ file with your favourite editor and hunt for the last mention of the file you need. I’m looking for “register.module.php”, so for me that looks like this:
r428 | mvoorberg | 2010-11-15 22:06:33 -0700 (Mon, 15 Nov 2010) | 2 lines
Changed paths:
M /faq.php
M /login.action.php
D /register.module.php

Use the following command to restore the file to the local filesystem at which point you can copy it out or do whatever you like with it. Notice the version number (427) is one less than the version that included the Delete action above.
> svn up -r 427 register.module.php

Once I copied the file out, I removed it again by simply running:
> svn up

Don’t forget to remove the ‘myLog.txt’ file when you’re done with it.

3 thoughts on “Recovering files deleted from an SVN repository”

    1. I’m not a Windows user, so that wouldn’t work for my situation. Also since I’m only interested in what the file looked like several months ago, not at the point where it was deleted, my SVN repository is the *only* place it’s available.

Comments are closed.