Subversion SVN Ignoring Files & Directories
Posted On: April 23, 2010 at 1:45 p.m.
Sooner or later while working with Subversion you will encounter files or folders that you don’t want to add to the repository. They might be hidden system files from Windows or Mac (.DS_Store, Thumbs.db etc) or they might just be programming files, such as .pyc files if you work with Python. We also exclude some directories of images etc that are dynamically generated by an application. You not only don’t want them included but it gets to be a pain to wade through all those files while trying to make a commit to a project. Lets make SVN ignore those files so we can move on with being productive!
To avoid these problems we use the svn:ignore property. To do this we’ll need to use the command line just a bit. Change directories in the command line to your project folder. Once there, lets take a look at the current status of a fictional directory.
svn status
Lets pretend it shows 3 files and one folder there to add or update in the repository like this:
test.py
test.pyc
DS_Store
images
We want to update the test.py file but we want to ignore all .pyc or DS_Store files and also the images directory entirely from now on. To do that, bring up the svn:ignore editor by doing this:
svn propedit svn:ignore .
Note that the above assumes you are in your SVN working copy directory, if not you would replace the trailing “.” with the path to your working copy.
You may also get an error like the following:
svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR is set, and no ‘editor-cmd’ run-time configuration option was found
In that case you need to set an editor for your shell to open this file with. This is set in a hidden file in your user directory on Mac’s, ~/.bash_profile (need to be able to view hidden files, or use Transmit). I prefer to open these with Textmate so I’ve added export EDITOR=’mate -w’ to my .bash_profile file. Then restart your terminal session.
To get it to ignore what we want I’ll add the following:
*.pyc
DS_Store
images
Thats it! Do a SVN commit to add these changes to the repository. Note that all working copies of the repository will be updated, so if you’re working with a team their local copies will ignore these files as well once they update.


Comments