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 since I recently deleted a whole bunch of files and I'm waiting to get them back, I'll show you how.
To recover deleted files from svn, first find the revision in which the file(s) existed:
cd /path/to/local/repository/ svn log --verbose .
I had a lot of files to recover, so I piped the output to a temporary file and cut out the junk I didn't need.
Second step, recover those files:
#!/bin/sh
REPO=https://svn.example.com/svn/repos/example/foo/
REV=11873 # one less than revision when file was deleted
FILES=- # pipe into this script your file names (like from xargs)
cat "$FILES" | while read file
do
d=$(dirname "$file")
if [ ! -d "$d" ]; then
mkdir -p "$d"
svn add "$d"
fi
svn copy -r $REV "$REPO/$file@$REV" "$d"
doneThis is not so easy for three reasons. First of all, if you have directories, you need to get their paths right and create new local directories for them. Second, if your file names have spaces in them, you need to quote those appropriately. Finally, you need to use a revision one less than the revision the files were deleted. In my example, I deleted the files in revision 11874. So I needed to copy the files as they existed in revision 11873.
Hooray, you now can recover deleted files from svn. Thanks to m0j0 for getting me started!
Trackback URL for this post:
Quick Links
| Software and Services | Customer Support | Company | Contact |
|---|---|---|---|
|
(800) 813-1316 |
PO Box 31407 Raleigh, NC 27622-1407
(919) 341-5170 — Direct (919) 521-4100 — Fax |

Comments
Post new comment