How to … Make Subversion ignore files and folders
December 10, 2006
Excluding files from your repository
Sometimes you may have types of files or folders in your source code tree that you do not want to include in your source code repository. Everyne developing with Visual Studio will immediately know what I mean: VS automatically makes bin and obj subfolders for your project folder in which it puts the buildresults and also creates *.suo files with your personal settings for a solution.
It would be convenient if we could exclude these files from our repository once and for all without having to manually uncheck them each time we update our project. Fortunatly, Subversion allows us to do this. In fact, there are two possibilities for exclusion.
With the global exclude we can exclude a certain type of file of being added to any repository to which a certain client connects. To do this, you must edit the Subversion “config” file which you can find in your local Application Data folder. A typical location for this file is: “C:\Documents and Settings\[username]\Application Data\Subversion”.
When you open this file, look for the section [miscellany]. In this section find a line with global-ignores and remove the “#” signes in front of it (if you haven’t removed them allready). Now add the files signatures you want to ignore.
For example, to ignore the suo files, we would write:
global-ignores = *.suo
The local excludes are made on folders. This means you can tell subversion clients to ignore a specific file, type of file or folder. This is done by setting the svn:ignore property on the target folder with the signature of the file or folder to ignore.
For example, to ignore suo files in the solution’s folder, you would perform following command in the folder of the solution:
[TargetFolder]>svn propset svn:ignore *.suo .
Do not forget the final dot, it means that the target folder is the current folder. With the above command Subversion will ignore all files with extension “suo” in the target folder.
To ignore folders we have a similar syntax. To ignore for eample a folder “bin” in our target folder execute following command:
[TargetFolder]>svn propset svn:ignore bin .
Again, do not forget the final dot, it means that the target folder is the current folder.
To ignore multiple types of files and folders, you must have a newline delimited list of values for the svn propset command. Because this can not be done with the commandline (well, I do not know how to do it anyway), we create a text file with on each line the signature of a file and/or folder to ignore.
For example, we have a textfile with following content:
We save this file in the target folder and name it “ignore.txt”, and then issue the command in the target folder
[TargetFolder]>svn propset svn:ignore -F ignore.txt .
Again, do not forget the final dot, it means that the target folder is the current folder. With the above command all folders with names obj and bin in the target folder will be ignored by Subversion.
 svn:ignore in the Subversion documentation
 global-ignores in the Subversion documentation
 Scott Sanders :: blog :: Ignore a file in Subversion (svn ignore) (The inspiration for making this a seperate post)
 svn ignore property wierdness
5 December 2006: original version