I know I’m going to forget how to do this, because I only ever need to do it once a year or something, so I’ll put it here for safe keeping:
To recover a file from svn that you deleted from your local repository, it’s first necessary to get the proper name of the file, and the revision of the repository it last existed in. To do that (assuming you don’t know, because if you do you have bigger issues), you go to the directory it was in (or as close as you can get to the directory it was in) and run:
> svn log --verbose
You should be able to find the file you’re looking for and the revision you need in the output of that command. Assuming your file’s name is ‘file.txt’ and it was in revision 250, you run the following to recover it:
> svn up -r 250 file.txt
Done. It’s there waiting for you. Enjoy. I had been fumbling around with ’svn co’ syntax until a digital buddy of mine corrected me. Thanks, Nivex!
Thanks
Comment by evansenter — April 22, 2008 @ 1:16 am |
Well actually you should
> svn log –verbose
find the revision where you deleted the file (suppose it’s r251) and subtract 1
> svn up -r file.txt
Comment by lrkwz — September 4, 2008 @ 4:05 am |
oops in my previous comment “svn up -r file.txt” should be
> svn up -r `revision number minus one` file.txt
Anyhow this leaves you with the original revision of the deleted file: the file hasn’t been recovered! i.e. if you `svn up` the file will go away again.
To fully recover files and directories you should
> svn cp -r 250 http://…/file.txt file.txt
where http://... is the repository URI
Comment by lrkwz — September 4, 2008 @ 4:30 am |
It can be quite hard to find the point in history where you deleted the file so I found this quite helpful
> svn log –verbose | grep -A5 -B5 file.txt
helps track down the revision when there’s lots of history
p.s. found this in google while trying to work out how to recover deleted files
good stuff thanks
Comment by James — April 2, 2009 @ 6:02 am |
[...] idea how to do it. Some quick Googling later and these are the commands I came up with (courtesy of the anonymouse geek at M0j0 (substitute 2064 with the revision number 1 before when you deleted the files, you can get this [...]
Pingback by Restoring deleted files from an SVN repository « simonwheatley.co.uk — April 29, 2009 @ 3:44 am |
[...] a task so seldom necessary that I can not remember what to do. So after googling I’ve found this blog-post. But it is not complete and a little outdated, so here is the way it has worked for [...]
Pingback by Virtualheadcrash » Blog Archive » How to restore a deleted file in svn — July 8, 2009 @ 3:22 am |
[...] Recovering deleted files from an svn repository « Musings of an anonymous geek How to recover a deleted file from svn (tags: svn tools software) [...]
Pingback by craschworks » Blog Archive » links for 2009-08-07 — August 7, 2009 @ 5:03 am |