SVN undo delete before commit

SvnDirectoryUndoDelete Directory

Svn Problem Overview


If you delete a directory from an SVN working copy, but haven't committed 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

Svn Solutions


Solution 1 - Svn

  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

Solution 2 - Svn

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.

Solution 3 - Svn

What worked for me is

svn revert --depth infinity deletedDir

Solution 4 - Svn

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

Solution 5 - Svn

To make it into a one liner you can try something like:

svn status | cut -d ' ' -f 8 | xargs svn revert

Solution 6 - Svn

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.

Solution 7 - Svn

You could remove the folder and update the parent directory before committing:

rm -r some_dir

svn update some_dir_parent

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLaCView Question on Stackoverflow
Solution 1 - SvnDenis BarmenkovView Answer on Stackoverflow
Solution 2 - SvnMichael HacknerView Answer on Stackoverflow
Solution 3 - SvnJasonView Answer on Stackoverflow
Solution 4 - SvnGreg HewgillView Answer on Stackoverflow
Solution 5 - SvnEarleView Answer on Stackoverflow
Solution 6 - SvnLaCView Answer on Stackoverflow
Solution 7 - SvnxinthoseView Answer on Stackoverflow