Musings of an anonymous geek

October 25, 2007

Recovering deleted files from an svn repository

Filed under: Sysadmin,Technology — m0j0 @ 9:13 pm

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!



  1. Thanks 🙂

    Comment by evansenter — April 22, 2008 @ 1:16 am | Reply

  2. 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 | Reply

  3. 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 | Reply

  4. 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 | Reply

  5. […] 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 « — April 29, 2009 @ 3:44 am | Reply

  6. […] 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 | Reply

  7. […] 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 | Reply

  8. […] Источники:, […]

    Pingback by Записная книжка » Как восстановить удаленный файл в svn? » Записная книжка — April 10, 2011 @ 3:39 am | Reply

  9. Actually the vanilla svn cp command above fails for me (and others – see As he points out:

    svn copy -r [revision] https://{URL}/canfield.conf@[revision] .

    Works *much* better!

    Comment by Stein Vidar Hagfors Haugan — October 18, 2011 @ 3:39 am | Reply

  10. Doh! I needed that file!…

    Every once and a while, I remove a file (or directory of files) from my local repository that I want back.  No big deal, it’s in the repository.  Well, yeah, but finding it and using the right command is not so straightforward.  And sin…

    Trackback by ideacode Software — October 21, 2011 @ 5:23 pm | Reply

  11. Thank you! You’ve saved my life.

    Comment by Ezequiel Lauría (@EzuEzu) — April 3, 2012 @ 8:51 pm | Reply

  12. machines a sous gratuites tomb raider 2

    Recovering deleted files from an svn repository | Musings of an anonymous geek

    Trackback by machines a sous gratuites tomb raider 2 — November 11, 2014 @ 10:37 pm | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

Create a free website or blog at

%d bloggers like this: