102

We have accidentally deleted the 'tags' folder from our Subversion repository where we only intended to delete one specific tag. What is the easiest way to get the 'tags' folder back?

We use TortoiseSVN as our client and I thought that when I go to the repo browser and show log, there will be something like "revert changes from this revision" similarly to what you can see in a similar dialog on your working copy. But there is no such command there...

Borek Bernard
  • 50,745
  • 59
  • 165
  • 240

7 Answers7

120

Just copy the deleted folder back from an earlier revision.

In the Repository Browser, click the button labeled HEAD (at the top-right corner) to show to a revision there your folder still exists, then right-click that folder and select "Copy to..." and enter the path there you want the folder to be re-created (probably the same path that is already in the text box).

Karsten
  • 8,015
  • 8
  • 48
  • 83
Mikael Sundberg
  • 4,607
  • 4
  • 32
  • 36
  • 4
    Great tip, thanks. One TortoiseSVN gotcha - in that "copy to..." dialog I had to change the path from 'example.com/svn/tags' to 'tags1' and then back for the OK button to become enabled. – Borek Bernard Feb 15 '10 at 11:22
  • 2
    This might be fine for tags, but should not be done to undelete any other folder since you will lose history – slckin Feb 24 '12 at 16:33
  • 3
    It does keep history, just did it also. – acdcjunior Aug 05 '13 at 13:47
  • just make sure you uncheck "Stop on copy/rename" when viewing the log, because otherwise TortoiseSVN will not show the history prior to your restore action (obviously)... – Oli Oct 31 '16 at 14:35
  • It totally worked. Saved a lot of my time. Thanks :) – dgupta3091 Aug 09 '19 at 09:27
80

for the command line enthusiasts:

  • first find the revision number where your delete happened:

    svn log -v http://svnserver/path/to/folderContainingDeletedFolder
    

say you find that the directory was deleted in revision 999 (btw: you might find it easier to find the revision number with the svn repo browser)

  • copy the folder from revision minus 1

    svn copy http://svnserver/path/to/folderContainingDeletedFolder/deletedFolder@998 http://svnserver/path/to/folderContainingDeletedFolder/deletedFolder -m "undeleted folder"
    

voilà you're done!

in your case this might be:

    svn copy http://svnserver/project/tags@998 http://svnserver/project/tags -m "undeleted folder"
raudi
  • 1,701
  • 1
  • 16
  • 16
11

Most of these answers will work to a degree but the correct answer is Daniel's. Do a reverse merge. That way you keep version history.

svn merge -r R1:R2

where R1 is the revision that you're at, and R2 is the revision that contains the deleted file/folder.

andrewsi
  • 10,807
  • 132
  • 35
  • 51
Miles
  • 119
  • 1
  • 3
  • 1
    In a reverse merge, R1 should be the revision you want to revert with R2 being the revision before that. – arleslie May 03 '16 at 17:47
  • 2
    You don't lose any history with `svn copy`. – maxschlepzig Nov 27 '16 at 23:13
  • For those of us who *aren't* command line enthusiasts, see: https://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-howto-rollback.html – Pascal Jul 24 '17 at 13:20
  • 2
    Wouldn't this restore all deleted files/folders? Would this work if I only want to restore one specific deleted folder but not other deleted folders? – OJ7 May 15 '18 at 19:36
7

You will need to do a reverse merge.

For details on how to do it (and pretty much anything else you would ever want or need to do with SVN), the official book is available online.

madth3
  • 7,275
  • 12
  • 50
  • 74
Daniel
  • 10,115
  • 3
  • 44
  • 62
3

Following on from raudi's answer which worked for me after this revision.

Some svn clients might need the revision number specified using the -r revision parameter instead of using @ after the folder as follows:

svn copy svn://svnserver/project/tags svn://svnserver/project/tags **-r 998** -m "undeleted folder"
Sirko
  • 72,589
  • 19
  • 149
  • 183
Paul
  • 51
  • 3
  • If you're restoring from a folder that still exists then `-r ` will work. However if you're trying to restore the folder directly you'll need to use `@`. Otherwise it'll tell you the file was not found. – arleslie May 03 '16 at 17:50
2

Goto Repository Browser of your repository, right-click on the parent folder where your deleted folder existed. Now, Show Log of the parent folder, and select the previous revision where you committed the delete operation. You'll have a list and right click on the folder from the revision info and select Update to this Revision.

You are done

Abdul Munim
  • 18,869
  • 8
  • 52
  • 61
  • Oh I see, it was not in the Show Log dialog but in the main repo browser window. Still, that command will attempt to update my local working copy while I'd like to fix this problem on the server directly (you can imagine that checking out hundreds of tags, each containing thousands of files, is not exactly what I'd like to do). – Borek Bernard Feb 15 '10 at 11:08
  • It worked for me. The context menu option (on right click) is "Revert changes from this revision" and it would reverse merge the changes. – hsg Apr 02 '19 at 10:21
0

Revert to the revision before the deletion

svn co -N https://svn.ex.com/repo/project/parentfolder@7537 .

svn copy https://svn.ex.com/repo/project/parentfolder/deletedfoldername@7537 deletedfoldername

svn commit -m "restoring" deletedfoldername