Restoring Deleted Files in SVN

From Zanecorpwiki

Jump to: navigation, search

Sometimes after doing 'svn rm aFile.txt', we find that wasn't really the thing to do. To get a file back, do:

svn cp https://x.racetechs.com/svn/main/trunk/foo/bar/aFile.txt@1000 ./aFile.txt

Assuming you were in the main/trunk/foo/bar directory, this would copy the (ostensibly last) version 1000 file back into the directory. To find the last version of a file, do

svn log --verbose | grep -A5 -B5 aFile.txt

This will find mentions of 'aFile.text' in the log and display them with 5 lines of context before and after.

Dealing with whole directories is a bit tricker. You can't 'cp' the directory (though I'm not sure why... svn cp + version not good? Anyway, I've had troubles with this. SVN can complains about some attic path not existing.) You might try the cp approach, but if that doesn't work, you're force to:

svn up -r 1000 theDir

This leaves you with a bunch of ".svn" dirs that confuse SVN to no end. This is probably not the best way to do it, but you can:

find . -name "\.svn" | xargs rm -rf
svn up
svn revert theDir
svn add theDir
svn commit -m "restored theDir"

Or something like that.

Personal tools