tail -f findings.out

« Python Tip: Create a test dictionary quickly

Tracking down used disk space: Follow largest directories »

Recursively ignoring multiple file patterns in subversion

There are a few filetypes that you likely don’t want to add into any subversion repository, such as .pyc, .log, and .bak files. Not only do they not need to be in the repo, but you also probably don’t appreciate them sullying the output of things like

1
svn status

either. Deleting all such files before each commit isn’t a good option either. SVN allows you to ignore certain file patterns in the current directory (assuming it’s under version control) and in all children via a command such as:

svn propset -R svn:ignore "*.pyc" MYDIR

But if you then try to add another pattern, such as “*.log”, the initial value of the svn:ignore property is overwritten! To overcome this, create a file containing the patterns you want to ignore, one per line. I created a .svnignore file and added it into my personal SVN, symlinked from my home directory. That way I can use it on each box I work on, on various repos as needed, since the patterns are pretty universal.

Say you have made a file called .svnignore containing:

1
2
*.pyc
*.log

Then you would run:

svn propset -R svn:ignore -F .svnignore MYDIR

And the two patterns in the file would be ignored in MYDIR and all its children. If you want to add or remove a pattern later, just change the .svnignore file and re-run the same command.

You can also setup such ignores globally for a given SVN repo, but I tend to shy away from that sort of change, since I might just decide that I want some logfile checked in at one point or another. Setting the patterns per repo allows for a bit more flexibility.

One annoying note: When you add new directories to your repo, you have to run the command again. Otherwise the svn options for the new folder won’t contain your ignore patterns.

Share and Enjoy:
  • email
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Technorati
  • Netvibes

Post to Twitter Post to Delicious Post to Digg Post to Reddit

Possibly Related (no promises):

  1. Easily sum matching file line counts
  2. Useful grep incantations
  3. Useful ways to list directory contents

Related posts brought to you by Yet Another Related Posts Plugin.

Tags: , , ,
January 5, 2009 - 11:14 PM
3 comments »
  • Kyle Banker

    March 12, 2009 | 2:45 PM

    It’s incredible that neither the official SVN Book nor the Pragmatic Version Control book discuss this situation. Goes to show just how clunky ignoring files in svn is.

    Anyway, excellent tip. Thanks so much!

  • Samuel Huckins

    March 13, 2009 | 5:15 PM

    Yeah, that giant book is stuffed with things I don’t need, and lacking in succinct descriptions of what I do. Glad this helped though!

  • katieg

    June 30, 2009 | 9:36 PM

    I use to love subversion, but then a year ago my company switched everything over to AccuRev, a scm tool that’s known for managing the software development process. I’m sure it wasn’t cheap. The only problem was that were weren’t able to transfer our history in SVN to AccuRev, but our performance and release quality has really improved, and AccuRev requires a lot less administration than than and Subversion did. But I still use subversion for my own small projects at home.

Leave a reply

Subscribe without commenting

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.