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?
If you are using TortoiseSVN, just do a Check for Modifications, sort by the Status column, select all the entries marked missing , right-click to open the context menu, and select Delete. Finally, commit to publish the changes to the repository.
Getting a deleted file or folder back If you have not committed a delete operation to the repository, then use TortoiseSVN -> Revert to retrieve the file. If you have already committed the deletion: Use the log dialogue box to find out the revision of your file.
If you want to undo all changes you made in a file since the last update you need to select the file, right click to pop up the context menu and then select the command TortoiseSVN → Revert A dialog will pop up showing you the files that you've changed and can revert.
svn revert will revert not only the contents of an item in your working copy, but also any property changes. Finally, you can use it to undo any scheduling operations that you may have performed (e.g., files scheduled for addition or deletion can be “unscheduled”).
If you just did
svn rm foo.txt
then you can undo that with simply
svn revert foo.txt
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:
svn merge -r123:120
Maybe first do a dry run to make sure it won't do anything you don't want:
svn --dry-run merge -r123:120
For the sub-question, how to remove a file from svn without removing the local copy:
svn rm foo.txt --keep-local
Or, of course, you could just copy to a temp file before svn rm'ing and then copy back:
cp foo.txt foo.txt-tmp svn rm foo.txt (svn ci -m "just removed foo.txt from the repository") cp foo.txt-tmp foo.txt
for whatever reason, the -r
arg wasn't working for me (svn version 1.6.9). I tried before and after the src
, 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:
svn cp url/to/removed/foo.txt@4 foo.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With