Michal Krasny
Michal Krasny

Reputation: 5916

How to prevent SVN restoring deleted files

I work in a team of developers and we don't have exactly separated code. So when I work on something for about a week, I need to do an update before i commit my changes. But when I do so, then all deleted files are restored. I know there is SVN delete operation, but it is annoying to do it for every deleted file or directory.

Is there any trick, how prevent this feature?

Upvotes: 14

Views: 5121

Answers (5)

Gabriel
Gabriel

Reputation: 635

To mitigate after the problem occurs, i do this:

  1. Select all the rows in tortoise svn window that were 'Restored', and copy
  2. Paste in second column of a new excel sheet
  3. in first column, type: del "
  4. fill the column with del " next to the restored files' paths, by double clicking bottom right corner of the first cell in which you typed del "
  5. fill after each path with a closing "
  6. Win+R (Start -> Run) notepad -> Enter. Copy all and paste into notepad. Select and copy one tab, Ctrl + H, replace all, replaces tabs with nothing to remove tabs
  7. Win+R cmd -> Enter , right click and paste the delete commands in command line, press enter and the files get deleted

I know these are a long list of instructions, but I believe they should be second nature to developers, and are necessary to know and go about quickly, for multiple purposes beyond this one, using excel this way, creating and running batch commands quickly, etc...

Upvotes: -1

Michael Cornel
Michael Cornel

Reputation: 4004

So, this is not basically a new answer but none of the existing seemed to fit to your exact question (and the problem I experience often).

Here is my approach: If you deleted files and don't want them to get restored during the neccesary update:

  1. Use TortoiseSVN function "Check for modifications"
  2. Order the list by Status
  3. Select all files with status "missing"
  4. Right click, delete

Of course this is "SVN delete", but this way you won't have to do it at the time you actually delete the files and are able to mark all of them in a batch.

Upvotes: 9

Ben
Ben

Reputation: 8905

I think you may be asking how to get a working copy where you can work on only part of a project at any given time, without having other parts of the project in your working copy at all.

Furthermore, I think you're saying that your current method, is to checkout the entire project, then manually delete items you don't want to see.

A better way, is to use the concept of a "sparse checkout".

In recent versions TortoiseSVN has a "Choose Items" button on the checkout dialog. This allows you to select with checkmarks every item you wish to include in your working copy. Other items will not be downloaded to your working copy when you checkout or update. The "Update to revision..." dialog also contains this "Choose Items" feature. Note this is "Right-click->TortoiseSVN->Update to revision..." not just "Right-click->Update".

You can also use "Update to revision" to set the depth to "exclude" for individual items if you only need to get rid of one or two.

From the command-line, "svn update" or "svn checkout" with the "--depth" option is the way to accomplish the same thing. Repeat as needed changing the "--depth" option to get a working copy with an arbitrary set of items.

Upvotes: 5

Edwin Buck
Edwin Buck

Reputation: 70909

There are two kinds of deletes here.

  1. Delete from file system (rm or delete).
  2. Delete from revision control (svn delete).

Make sure you know which kind you are doing. If you are deleting from the file system (local machine) only, then when you ask to update to the latest in your repository, you should get the file back.

If you are deleting from revision control, then it is a svn change operation, and will not apply to the repository until you run svn commit. After that as others update, svn will remove the file from their repositories.

Note that this does not mean that it is impossible to get a copy of the file. SVN keeps a full history of every revision, so if you request the non-current revisions that have a copy of the file, you will get a copy of the svn deleted file as it was in that revision.

In the rare case you really want the file gone from the historical records too, you need to do some scripting. Basically, you will be creating a new repository which mimics the old one (minus the file). To do this

For each revision number from 1 to current.

  1. get the files from the old repository.
  2. remove the offending file.
  3. commit to the new repository

Keep in mind that this can be a bit difficult to do well, as you will need to come up with solutions to preserve the meta-data, like file permissions, commit messages, svn properties, commit times, and commit user names.

I highly recommend against rebuilding your history this way, unless there is some globally overriding reason to do so, like a court order.

Upvotes: 4

SilentBob470
SilentBob470

Reputation: 79

You must delete the files via svn. It has to 'know' that you want to have them deleted. If you don't use svn to delete them, it seems they are missing so the update restores them.

the steps are:

delete locally: $ svn delete somefile

commit the deletion to the repository $ svn commit -m "Deleted file 'somefile'"

Upvotes: 2

Related Questions