Ignoring files with SVN

I’m using SVN for my XCode projects, but have soon realised that XCode support for SVN is not powerful enough. So I have decided to go the old good command-line way…

One of the most fundamental things I want to be able to do is ignore files – there is a lot of stuff in my projects that I do not want to go into my SCM tool: data files, build files, and so on. Subversion offers an ignore feature, but I wasn’t able to use it through XCode, so here goes.

First of all, the theory. Each file in SVN can hold various custom properties (metadata) that you can manage using the propset, propdel, propget, propedit or proplist commands. Properties starting with svn: are reserved for use by the tool itself. One such property is svn:ignore, that applies to directories only and lists file names or patterns that should be excluded from SVN operations.

Properties are stored on the SVN server itself, so that wherever and whenever you check out your projects, you will be taking the properties with you. There is a way of saving this type of information on the client, so that ignoring will only be applied for the user or on the computer where it is defined. But it is not what I need at the moment. The feature is called Runtime Configuration Area and a detailed explanation can be found here.

Back to SVN properties for ignoring files, let’s move on to the practice. After cd‘ing into the folder where files should be ignored, the following command

svn propset svn:ignore "*.abc" .

will make sure that SVN commands ignore any files with extension abc in the current directory (that’s the final dot). More patterns or file names are separated by a new line, which results in an awkward (but working) syntax:

svn propset svn:ignore "readme.txt
logfile.*" folder

With this one you exclude readme.txt, all files with abc extension and all files starting with logging. from SVN operations on the folder subdirectory of the current directory. Because in Windows this multi-line syntax is not possible, the svn propedit command can be used to open up an editor where you can type in your patterns on as many lines as you need.

svn propedit svn:ignore folder

The property value here is not specified as it will be entered in the editor that the command will launch for you. Alternatively you can create a file with all of your patterns (one per line as usual) and issue the command with the -F option

svn propset svn:ignore -F patterns.txt .

According to ThoughSpark.org, SVN uses the fnmatch function for matching your patterns, so anything should go that the function would accept. This is the general idea, though

Pattern Meaning
* matches everything
? matches any single character
[seq] matches any character in seq
[!seq] matches any character not in seq

Finally, the commands propset and propedit only apply their configured values to the directory specified. You will need to run the commands on all subfolders if the property is to be set on them too. Or you can use the -R (recursive) option

svn -R propset svn:ignore -F svnignores.txt .

The official documentation for this topic is available here.

Leave a comment

Your email address will not be published. Required fields are marked *