These instructions are a little intimidating and confusing: http://svnbook.red-bean.com/en/1.0/ch04s04.html#svn-ch-4-sect-4.3 .
And also they don't seem to mention that it's much simpler if you haven't yet checked in after doing the "svn rm
" [1].
So I thought this would be a good place to record a simpler answer for those googling for this.
[1] To an svn newbie, it might appear that "svn rm
" immediately destroys the file. I recall doing svn rm
thinking that would just remove it from source control and freaking out when the file itself actually disappeared. So a sub-question is, what's the right way to remove a file from version control without actually removing your local copy?
for whatever reason, the
-r
arg wasn't working for me (svn version 1.6.9). I tried before and after thesrc
, but kept getting a message that the file was not found in the current revision (duh). Same with --revision. Using the @ style syntax worked though:To remove a file but keep it in the working copy, use
To get a file back after you've committed the remove, you can use either the merge command, or the copy command - both will preserve the file history. Since the merge way is already described elsewhere, here's the copy way:
To revert a deleted file in SVN. Find the revision number just before delete (say 341). Then revert that file alone to that revision number.
For TortoiseSVN users, this is very easily accomplished via the Repo Browser. Within the Repo Browser switch to the revision before the file was deleted (you can change the version using the "Revision:" button at the top right):
You should then be able to see the deleted file in its original location in the Repo Browser. Right-click on it and choose "Copy to working copy...":
The file will then be restored to your working copy ready to commit (as though svn added) and with its log history intact.
If you just did
then you can undo that with simply
If you already checked in after doing the "
svn rm
" then you can look at the log (svn log
), find the last revision where the file existed, and grab it from that version.One way to do that is to merge in the old revision that has the file. Assuming the current revision is 123 and the last version with that file is 120, then do this:
Maybe first do a dry run to make sure it won't do anything you don't want:
For the sub-question, how to remove a file from svn without removing the local copy:
Or, of course, you could just copy to a temp file before svn rm'ing and then copy back:
i used the copy menu item from the previous revision using tortoise, worked for me and kept the history.