How to remove a file from version control without deleting it?

SvnVersion Control

Svn Problem Overview


If I run svn rm file, the file is removed from the local working copy.

What I do now is:

$ cp file file2
$ svn rm file
$ svn ci
$ mv file2 file

How do I avoid svn also deleting the local file when using svn rm?

Svn Solutions


Solution 1 - Svn

You want the --keep-local command-line option. This removes the file from version control without removing it from your filesystem.

$ svn rm --keep-local my_important_file

Note: The --keep-local only affects the svn rm of your copy. Other users may have their own local copy of the file deleted unless there is a conflict between their local copy and the repository due to changes they have made. This may not be the desired outcome. See comments below.

Solution 2 - Svn

Removing a file from SVN without deleting it locally nowhere is a common problem. One prominent example is the file .classpath in an Eclipse project. Putting this configuration file under SVN is marvellous as long as all machines used in the project have the same Eclipse and Java installation. Once this condition is violated commits start to break other Eclipse projects. This is the point one has to remove a file from SVN without deleting ist anywhere.

svn rm --keep-local .classpath

does the job perfectly on one machine and at that point in time.

Problem is other machines may lose that file (on update) or resurrect it (on commit). SVN's flaw is neither to handle --keep-local in the repository nor to propagate it to other working copies. Hence on all other machines above command has to be executed — best before any commit or update.

This, of course, will work 90%, at best. Deletes and re-versionings will happen out of a sudden. My solution is to have every machine, I have direct or indirect access to, do

svn rm --keep-local .classpath
copy .classpath .classpath-nameOfTheMachine
svn add .classpath-nameOfTheMachine

This is so outright ugly to be hardly called a "solution". Nevertheless it always allowed quick repairs of any later accidents.

Solution 3 - Svn

I do not have an answer to this precise question, but I do have an answer to a related question, which is how to remove all files (i.e. not a specific one) in a directory from version control without deleting them locally. This solution comes from a Scientific Linux implementation.

ls -a .svn

should show the svn directory that stores control data. Simply:

rm -r .svn

will get rid of this directory. Then typing:

svn status

will produce a 'warning: this directory is not a working copy' error, because it is no longer under version control.

I hope this helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJuanjo ContiView Question on Stackoverflow
Solution 1 - SvnAndres Jaan TackView Answer on Stackoverflow
Solution 2 - SvnAlbrecht WeinertView Answer on Stackoverflow
Solution 3 - SvncjamesView Answer on Stackoverflow