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.

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

About these ads

44 Responses to “How to … Make Subversion ignore files and folders”

  1. Mikhail Vlaimirov Says:

    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. Nolan Says:

    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. Rene Says:

    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. Hi Rene,

    that is indeed the idea.

  6. sundeep Says:

    Do i need to go to each folder and set the ignores or can i do it only on the top folder?


  7. No, I just had a try and setting it on the top folder is sufficient.

  8. Slavi Says:

    I’ve read on a site that you should commit after propset.

    Have you done that ?

    Slavi


  9. Hi Slavi,

    I did indeed do this. The property is set on the server so you must commit your changes.

    Serge

  10. Jan Says:

    Thanks for the svn tips

  11. bwo Says:

    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.


  12. You can easily put in new lines on the command line. Just use a quote… e.g.

    svn propset svn:ignore “first
    second
    third” .

    works fine.

    Scott

  13. George Says:

    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

  14. anbo Says:

    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’ .

    • geronimo Says:

      `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.


  15. [...] this solution is adopted I need to add svn role to ignore SharedLibs in each sample applications folder. Tagged with: Rhino-Tools, svn:ignore « Preah [...]


  16. [...] References: Howto User Rails With Subversion Preparing a Rails Application for SVN (global-ignore) How to … Make Subversion ignore files and folders (svn -F [...]

  17. ct Says:

    I accidentally ignored a file. How do I undo it?

    Thanks!

  18. ktulhu Says:

    @ct
    use svn propdel command
    read svn help propdel before

    • geronimo Says:

      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 – .’

  19. Olaf Says:

    Thanks! I had to configure svn for a continuous integration server and your post helped a lot!

  20. John Says:

    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.

  21. Steve Says:

    Thanks – that’s a useful post!

  22. Mayank Says:

    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.

  23. forex data Says:

    Not many people know what is being shared here. Thanks for sharing it with us.

  24. Guido Says:

    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?


  25. [...] Two ways to Make Subversion ignore files and folders, suo file etc two ways: 1. Add to Ignore list [...]

  26. sandrar Says:

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.


  27. [...] 4. Ignore files and folders from repository [...]


  28. Thanks for sharing. It was useful.

  29. ukchucktown Says:

    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 -

  30. Sam Watkins Says:

    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.


  31. [...] as images, views, css files and others will need to be different from instance to instance. I found an excellent tutorial on ignoring files, but that’s when I hit the snag: since I put everything under revision [...]


  32. [...] this requires an additional file. I found the solution in the comments of this article: You could just open quotes and then enter newlines on the command line itself, [...]


  33. Thanks for the useful post. Soon I will finally get rid of SourceSafe!

  34. Alan Morgan Says:

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

    svn propedit svn:ignore .

  35. Eoin Says:

    Reblogged this on Magp.ie and commented:

    Here is a good guide on how to exclude files and directories from SVN.


  36. [...] Since you’ll never be needing to add or commit any changes to any files in the Library folder, you might find it nice to have SVN setup to ignore those files. Here’s an article that will walk you through the process. [...]


  37. [...] Add a local rule: svn propset svn:ignore *.php . (Do not forget the final dot) [Ref] [...]


  38. [...] How to remove a file/folder from a SVN repository and add to the ignore list How to … Make Subversion ignore files and folders [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: