tags:

views:

9418

answers:

4

This sounds like a manual question to me but I can't find it. Suppose we have a repo with files and directories in it that shouldn't be under version control but rather should be on the ignore list (such as Eclipse files .settings, .project, generated doc files - things that should never have been added and committed in the first place). What is the best way of deleting these files from the repo and moving them straight onto the ignore list?

Update: The accepted answer below details a good way of setting up your local subversion repositories to avoid the problem described above. However, if you still have to solve this, it seems that you have to do some manual fiddling to get files/folders out of the repo and onto the ignore list.

For instance, for the .settings folder, first add this to the global ignores list then run the following command:

$REMOVE=".settings"
cp -r "$REMOVE" /tmp/ && \
svn rm "$REMOVE" && \
svn commit -m "Moving to ignore list" "$REMOVE" && \ 
mv "/tmp/$REMOVE" .

This copies the file/folder to a temporary location then removes it from SVN and commits the remove - finally the file/folder is copied back but as it is now on the ignore list it will be ignores by SVN.

A: 

svn remove filename

ignoring: svn propset svn:ignore filename|pattern

see also: http://sdesmedt.wordpress.com/2006/12/10/how-to-make-subversion-ignore-files-and-folders/

Kevin Davis
Subversion does not have an *ignore* command. You must add the svn:ignore property to the directory or edit the subversion config file for global ignores
Jason Coco
yikes, sorry about that it's been a while ;-) corrected my response
Kevin Davis
A: 

If you want them gone forever (or till you add them yourself back), you svn rm them, commi that and add them to .svnignore.

Keltia
There is no .svnignore file. Subversion configures global ignore patterns in its config file (which lives both at the user and host levels), or the svn:ignore property on directories (which lives at the project level and is versioned).
Jason Coco
+5  A: 

There are two ways with subversion, one is specific to the user and the other is actually maintained in the repository (and therefore effects everyone).

For a list of globally ignored files (exclusive to each user/machine), you need to edit the subversion config file and alter the global-ignores directive in the miscellany section. The config file is documented and the syntax is very simple. For example:

global-ignores = *.o

On a UNIX system, the config file is found at ~/.subversion/config. On a Windows system, the config file is found at %APPDATA%\Subversion\config or in the registry under HKCU\Software\Tigris.org\Subversion\Config.

Once you set this up, you will never accidently add these files to your repository, nor will the files show up as ? in your svn stat commands. If your repository already has these files, it probably won't hurt to leave them there as they are, but changes and modifications to the files will be ignored in the future.

To set this up on a per-project basis (which will effect anyone checking out the project), you would add the svn:ignore property to the project directories where files are likely to be stored. For example, to exclude a directory named build from the top-level of your project, you would do something like this:

svn propset svn:ignore 'build' .
svn commit -m 'project ignores build directory' .

From now on, the build directory in your project will be ignored by subversion. For more on this, see the documentation at http://subversion.tigris.org/ or issue the svn help command for more information.

EDIT: Added more based on comment... dunno how I missed that part of the original question!! Sorry :)

Unfortunately, removing the files that you now want ignored from the repository is a manual process, although, if you know exactly which files they are, you could write a little script that people having this problem could run (in the future, the svn:ignore property would keep them from ever having to repeat it, and it has the advantage of being able to be easily modified when the need arises).

To remove the files that you don't want from the repository, but keep the local files around, follow these steps:

  1. Create either your global-ignores entry or add the svn:ignore property to your repository and commit.
  2. For each file that you want to remove from the repository, issue this command: svn rm --keep-local filename
  3. Once you've issued the svn rm command for each file, commit your working copy.

Because this may have the side-effect of deleting files from people's current working copies if they haven't updated their config files, I highly recommend using the svn:ignore property on the repository directories. That way, when people update, they won't unexpectedly have files deleted because they haven't modified their global-ignores parameter yet.

Jason Coco
That's a good explanation of the correct set-up and I will henceforth ensure my global ignores file is adjusted to void this happening. It doesn't answer my original problem though of removing a file from SVN and having it ignored without having to delete the file and replace it.
DavidWinterbottom
hey David - sorry about that, I guess I didn't read the question properly :) I've updated the answer a bit at the bottom... HTH! J
Jason Coco
A: 

Thanks for this answer exactly what I needed. One thought on the final script outlined above, wouldn't it be better in your script to do a svn export instead of cp -R? That way you'd get clean folders without any of the .svn folders.

e.g.

$REMOVE=".settings"
svn export "$REMOVE" /tmp/ && \
svn rm "$REMOVE" && \
svn commit -m "Moving to ignore list" "$REMOVE" && \ 
mv "/tmp/$REMOVE" .

Anyway just a thought ...

Mark Steudel