Skip to content

Undelete file/folder using SVN

April 16, 2010

Short post. At CERN we are now moving repositories from CVS to SVN. One missing feature among the users/adopters was this Attic that is a folder showing all deleted files. This was nice to have if you ever needed to undelete an old file for some strange reason. How do you undelete a file in SVN? Answer is, it is not all that easy! A good tutorial is given here. I expanded on that tutorial a bit, making a bash function you can put in your ~/.bashrc script (i.e. the file that is executed each time you start up a bash shell). I copied the code to pastebin, so you can see it nicely presented with syntax highlighting, see here.

When you have added this function, you can undelete a file simply by the command “svnresurrect <filename>”. Note that this also works for folders! Further, if you do not know the specific name, “svn log -v | grep “^ *D” will show you a list of deleted folders/files. Even further, notice that the function only iterates through revisions that had changes in current subfolder, so it will go quicker if you execute it in a subfolder with fewer changes…

Do you have suggestions for improvements of this script? Do you have problems using this tip? Do you see errors? Comments are always welcome! 🙂

Edit: I decided the code insertion in WordPress is unreadable, so please LOOK HERE instead, the pastebin entry is set to not expire.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: