Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete file from the working copy only but not from the repository

Tags:

svn

Since I could not find the answer of the above question anywhere in the web, I come with the solution myself. It's a manual process but I couldn't find any other standard solution. So here it is:

Suppose you want to delete the file test.txt from directory work. Now if you delete test.txt forcefully by

rm -rf test.txt

command then on the next svn up on the work dir (or any of its parent-directories), the file will be restored. So the trick is to delete it from .svn/entries file, as well. Thus the complete sequence of commands for deleting test.txt only from working copy is:

cd work
rm -rf test.txt
svn st     #it shows ! sign beside test.txt which means that 
       #in the next **svn up** it will be restored
chmod u+w .svn/entries
vi .svn/entries
#delete the lines associated with test.txt
#you need to delete the following 3 lines from .svn/entries
#test.txt
#file
#^L
svn st #it doesn't report test.txt anymore
like image 207
user2426277 Avatar asked Jul 10 '13 22:07

user2426277


People also ask

How do I delete a working copy in SVN?

If you have a working copy which you no longer need, how do you get rid of it cleanly? Easy - just delete it in Windows Explorer! Working copies are private local entities, and they are self-contained. Deleting a working copy in Windows Explorer does not affect the data in the repository at all.

How do I delete files in git but not locally?

Using the git rm –cached Command We've mentioned that git rm FILE will remove files from the index and local working tree by default. However, the git rm command provides the –cached option to allow us only to remove files from the repository's index and keep the local file untouched.

How do I remove a file from a git repository?

The git rm command can be used to remove individual files or a collection of files. The primary function of git rm is to remove tracked files from the Git index. Additionally, git rm can be used to remove files from both the staging index and the working directory.

How do I delete a file from SVN repository?

To remove a file from a Subversion repository, change to the directory with its working copy and run the following command: svn delete file… Similarly, to remove a directory and all files that are in it, type: svn delete directory…


1 Answers

lallafa reports a good method, based on something called sparse directories:

svn update --set-depth exclude <folder-to-delete>
  • nice
  • easy
  • works on files

not good if:

  • I guess won't help you avoid checking out GBs of data you have (although you could try this.)
  • doesn't work on switched directories (may or may not with a little work, not tested)
  • on large directories, not a very good idea. od_m3 says that on a 190 GB working copy, with svn 1.6 this method tooks 1 hours, but on svn 1.7 it tooks more than 50 hours. This was in 2011.

added from source:

if you later want to use that directory again, you can do

svn update --set-depth=infinity <folder-to-delete>

I wish I knew how can I list directories already "excluded" this way, because st won't show them. :D


another method from same source by someone called 'Mike5' (or jed/jeds) that works on directories:

for every directory you want to avoid updating, do

svn switch --ignore-ancestry http://dummy/exists/but/empty_folder some_folder
  • replace some_folder with the folder you want to ignore.
  • also replace http://dummy/exists/but/empty_folder with an existing path in your repository which is an empty directory, will never be updated nor deleted - supposedly created and dedicated for this purpose.

By this, you will achieve:

  • switched directories not updating any more in the working copy
  • no changes to the actual repository

You will not achieve:

  • anything on files
  • the directory won't disappear/be deleted (from file listing)
  • getting rid of initial checking out of these directories, unless you do a checkout for 'immediates' with --depth, first, do this, and then continue the checkout (not tested).
  • I guess you cannot get rid of downloading GBs of data you already have (not tested).

It is also a good idea to use svn propset svn:ignore "*" empty_folder on the dedicated empty directory, so noone can commit anything to it.

like image 53
n611x007 Avatar answered Sep 25 '22 23:09

n611x007