Juanjo Conti
Juanjo Conti

Reputation: 30023

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

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?

Upvotes: 136

Views: 93385

Answers (4)

Pawan Kumar
Pawan Kumar

Reputation: 309

for those who use GUI on svn, use below steps to remove a file from svn version control but retain it locally. enter image description here

Upvotes: 2

Andres Jaan Tack
Andres Jaan Tack

Reputation: 23014

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.

Upvotes: 289

Albrecht Weinert
Albrecht Weinert

Reputation: 146

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.

Upvotes: 13

cjames
cjames

Reputation: 1

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.

Upvotes: -4

Related Questions