How to … Make Subversion ignore files and folders

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.

Global exclude

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

Local exclude

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:

obj
bin

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.

Resources

[1] svn:ignore in the Subversion documentation
[2] global-ignores in the Subversion documentation
[3] Scott Sanders :: blog :: Ignore a file in Subversion (svn ignore) (The inspiration for making this a seperate post)
[4] svn ignore property wierdness

Updates

5 December 2006: original version

44 thoughts on “How to … Make Subversion ignore files and folders

  1. Consider the following situation: there is source files of some project inside SVN repository. I have working copy of this files on my local computer. I use some sort of IDE to edit them. This IDE creates it’s own auxiliary files (such as project settings) is the directory containing working copy. Compilation output is alse placed there (actually in ‘bin’ subfolder that is not under SVN control). I want subversion to ignore such auxiliary files and output folders, but in fact other developers of this project use another IDEs and another names for output folders. So I want my ignore list to be local. With CVS I can list my ignores inside unversioned .cvsignore file. Is it possible to set svn:ignore property locally so my changes to this proeprty will be commited to repository?

  2. I’m not faimliar with CVS, but from wath I read here I think you’re out of luck with Subversion. The closest you can get is to edit the ignore section in the Subversion config file, thus using global ignores.

  3. Thanks, I’ve been trying to figure out how to set multiple ignores. I did find a way to ignore multiple files/folders without a text file though… just start out with

    >svn propset svn:ignore ‘file1

    press enter, it will take you to the next line…

    >file2’ .

    pressing enter again will run the command with the two files/folders on separate lines. You could continue adding more lines by just not closing the quotes

  4. After adding a file to the ignore property, subversion wants to commit changes from the topfolder (which contains the property). Does this mean that the property is defined as server side property which will change all other users ignoring-behaviour? thanks.

  5. Another tip. You can set properties with any text editor (for example, notepad.exe on windows), by 1)defining an environment variable SVN_EDITOR, then 2)using the command ‘svn propedit’.

    For example, on Windows/DOS, you would do:
    D:\> set SVN_EDITOR=notepad.exe
    D:\> svn propedit svn:ignore .

    You simply save the file, and SVN will use it for the properties.

  6. In bash it’s pretty simple to go through and set a bunch of the same filenames to ignore all at once. As in an example above, create a ~/ignore.txt file with what you want to go into the ignore list separated by line returns. like:
    bin
    obj
    lib

    Then run this from command line or a script:

    basedir=”$PWD”
    dir_names=”dir names to run through separated by a space”

    for name in $dir_names ; do cd $name; svn propset svn:ignore -F ~/ignore.txt .; cd $basedir; done

  7. For me (bash on linux/ubuntu) the
    [TargetFolder]>svn propset svn:ignore *.suo .
    only sets the property for the first file which matches the pattern *.suo .
    So the pattern has to be quoted:
    [TargetFolder]>svn propset svn:ignore ‘*.suo’ .

    1. `svn propset svn:ignore *.suo .’ as long as there is no file ending in `.suo’ in your current directory. Otherwise the Shell (bash, sh, etc) will match `*.suo’ and and call that svn command with those matching files, i.e. `svn propset svn:ignore a.suo b.suo .. z.suo .’ Svn will then use a.suo as argument for `propset’ and set property `svn:ignore’ on `b.suo ‘.. `z.suo’ and eventually on `.’
      If however no .suo file exits in the current folder, then your Shell will not expand `*.suo’ and passes that string as is to Svn.

    1. With all respect but `propdel’ is the wrong answer – in almost all pratical cases! Usually svn:ignore contains a couple of file patterns to be ignored (would be rather convenient if Subversion would allow for more advanced matching patterns).

      Apply `propdel’ and all your patterns are gone. Rather use `propedit’ invoking an editor of choice and remove the offending pattern.

      Or use `propget’ to pump your patterns into a file, remove the offending pattern and reset the property from that file again:

      `svn propget svn:ignore . | sed -e ‘s/^{pattern}$//g’ | svn propset svn:ignore -F – .’

  8. Thanks for the post. For me, thumbs.db files always get versioned by mistake – are totally pointless and they are almost always the ones that Subclipse hangs on. It’ll great to be rid of the damn things.

  9. I need to ignore ‘Cache’ folder form the SVN update/commit. But the problem is it is already committed in the SVN Repository. How can I do the task? Please help.

  10. I need to ignore everything in the folder “/tmp” with the exception of one file (“/tmp/restart.txt”). Does anyone know how to implement that in Subversion?

  11. I really didn’t see anyone demonstrate a way to add multiple files and folders from the command-line without a text file. Using echo and a pipe you can avoid the text file.

    echo -e “processed\nto_process\nunprocessed” | svn propset svn:ignore . -F –

  12. or you can type the newlines directly in a quoted string:

    svn propset svn:ignore ‘processed
    to_process
    unprocessed
    ‘ .

    I prefer to use a file for this because it’s easier to edit the list.

  13. Since this is still being indexed by Google… the better solution for multiple files is:

    svn propedit svn:ignore .

Leave a reply to kubino Cancel reply