tags:

views:

3615

answers:

4

If you delete a directory from a SVN working copy, but haven't commited yet, it's not obvious how to get it back. Google even suggests "svn undo delete before commit" as a common query when you type "svn undo d", but the search results are unhelpful.

edit: I'd like a solution that works in subversion 1.4.4

+1  A: 

The simplest solution I could find was to delete the parent directory from the working copy (with rm -rf, not svn delete), and then run svn update in the grandparent. Eg, if you deleted a/b/c, rm -rf a/b, cd a, svn up. That brings everything back. Of course, this is only a good solution if you have no other uncommitted changes in the parent directory that you want to keep.

Hopefully this page will be at the top of the results next time I google this question. It would be even better if someone suggested a cleaner method, of course.

LaC
That is assuming there are no subdirectories in the parent that have pending changes.
Russell
+2  A: 

Do a (recursive) Revert operation from a level above the directory you deleted.

Greg Hewgill
This will obliterate WAY more changes than necessary.
Michael Hackner
That does not work with Subversion 1.4.4 (I've just tried it). svn help revert even says "this subcommand does not require network access, and resolves any conflicted states. However, it does not restore removed directories." I'm sorry, I should have specified the version. 1.4.4 is what comes with Mac OS X 10.5.
LaC
+11  A: 

svn revert deletedDirectory

Here's the documentation for the svn revert command.


EDIT

If deletedDirectory was deleted using rmdir and not svn rm, you'll need to do

svn update deletedDirectory

instead.

Michael Hackner
That must be new, it doesn't work in SVN 1.4.4. (It was the first thing I tried.)
LaC
This is what 1.4.4 says, btw:$ svn help revertrevert: Restore pristine working copy file (undo most local edits).usage: revert PATH... Note: this subcommand does not require network access, and resolves any conflicted states. However, it does not restore removed directories.
LaC
1.6.6 has the same text in the help, but it worked for me when I tested it. Note that if you did not use `svn delete` to delete the directory, but instead deleted it using `rmdir`, you'll need to `svn update deletedDirectory` instead.
Michael Hackner
I have deleted one file (svn del) from a local svn-ed directory. svn update did not work but svn revert worked. I was using SynchroSVN for Mac. However, thanks for the tips.
karim
+1  A: 

1) do

svn revert . --recursive

2) parse output for errors like

"Failed to revert 'dir1/dir2' -- try updating instead."

3) call svn up for each of error directories:

svn up dir1/dir2
Denis Barmenkov