Usha Guduri

SVN Delete - an oops moment!

And how many times did you accidentally delete files from svn repo - be it because you were copying and instead moved, typo’d and deleted 1 file instead of another or for whatever reason?!

Easiest to do: simply copying the file from elsewhere and svn add

Better way to do: restore the files, including the svn history.

To see which revision deleted the file, foo.file

1
2
3
$ svn log -v 
r100 | me
D <local_path>/foo.file 

Now copy the file from the previous revision using the repo url, not just the location on the local machine

1
2
3
4
5
6
$ svn copy -r 99 http://<svn_repo_path>/foo.file@99 <local_path_to_foo.file>/.

$ svn status
A <local_path>/foo.file

$ svn commit

And now the svn log still shows the entire history without the deletion

1
2
3
$ svn log <local_path>/foo.file
r101 | me | adding back foo.file
r99 | me | last known valid change

Comments