Thursday, April 10, 2008

Restore a Deleted SVN Directory

Occasionally when working with a group of developers, someone (and I'm not going to name names...) will accidentally delete an entire directory of the subversion trunk and commit that change. Luckily, it's not the end of the world if this happens. Change directories into the root of your subversion source tree and issue a merge command as follows:

svn merge -r [bad revision]:[good revision] .


example:

svn merge -r 13831:13830 .

After that, checkin your changes, and you're back in business. You can determine revision numbers by doing something like:

svn log -v . | less

3 comments:

Steve Laniel said...

svn merge -c -[revisionNumber]

works in recent versions of svn, as a shorter alternative to

svn merge -r [newRev]:[oldRev]

I find the '-c' version is easier to script. With the -r, you need to look through 'svn log' or somesuch to find the revision number just before the one you want to back out.

Travis Whitton said...

Good tip... appreciated!

Anonymous said...

About finding the previous rev, I have found that you can always specify REV-1, even if it was not modified. svn will merge to the state as of REV-1, even if it was not modified in the rev.

Thus, diff -r9812:9813 shows the changes made in 9813.