SVN (Subversion) is a version control system that is used by WordPress and thus by all our developers at rtCamp.
Many a times, while cleaning up our repositories, we end up deleting the wrong files and/or directories. If a top-level directory gets deleted accidentally, one usually starts sweating!
The simplest command to restore/revert deleted file/directory in SVN is:
svn cp http://svn.example.com/path/to/deleted/dir/@REVNUM http://svn.example.com/path/to/deleted/dir/
In the above command,
- cp is shorthand for copy command 😉
- http://svn.example.com/ is the location of SVN-repo
- /path/to/deleted/dir/ is actual path of file or directory to be restored (including filename/directory-name)
- @REVNUM is the old revision number in which that file/directory was present last-time
Note that SVN paths for source and destination are same in such copy commands!
Example: Below is an example usage
svn cp http://svn.example.com/wordpress/themes/@286 http://svn.example.com/wordpress/themes/
If for some reason above command-syntax doesn’t work, try alternative syntax as below.
svn cp -r REVNUM http://svn.example.com/path/to/deleted/dir/ http://svn.example.com/path/to/deleted/dir/
Q. How to find old REVNUM i.e. revision number?
There are many ways. The simplest one is, if you have noticed the accidental delete quickly enough, notice the current version number and try using a number smaller than one!
Alternatively, you can use SVN browser, just Google for one. If you are using NetBeans or any other nice IDE for development, try using for built-in SVN browser/tool in that IDE.
Q. Why don’t we just use ‘revert’ command in SVN?
‘revert’ command in SVN, rolls back local changes on local working copy only! Though I wish it should have been designed to roll-back changes in remote copies as well.
This unexpected behavior from revert command is one of reason why people starts sweating then they delete a folder in SVN accidentally.
Let me remind you, you can never loose data in SVN itself. So be calm and try some other article from Google search, just in case this doesn’t work for you! 😉