How To Manage Configuration Files With Subversion August 3, 2009

Configuration files get changed every time you install an instance of a project. Then they sit there, annoying you every time you do a commit. OK, maybe not you. But certainly me. Here’s how to ensure they never get in your way again.

There are two aspects of this principle:

  1. Use configuration templates
  2. Ignore configuration files

Also useful is the idea of a versioned ignore file, which will help you with things like generated or compiled files.

Setting Up A Config File In A New Project

First copy your current config file to a template. Then add it to Subversion.

$ cp config.php config.template.php
$ svn add config.template.php

Now delete your old config file.

$ svn remove config.php

Next you need to ignore config files from here on. We’ll use an ignore file for this, so that we can ignore other files, and easily manage what we are ignoring.

Create a file called .svnignore in the root directory of your project. Add “config.php” to it, and any other files you’d like to ignore. I like to ignore my Komodo Project File too. e.g.


And tell Subversion to ignore the files listed, and add the ignore file.

$ svn propset svn:ignore -F .svnignore .
$ svn add .svnignore

Then commit.

$ svn commit -m "Now ignoring config"

Converting An Old Project

If you follow the instructions above, and you update an installation, you will end up deleting your config file. Oops! To avoid that, FIRST WARN ANYONE WHO MIGHT END UP WITH A DELETED CONFIG FILE, and when you update, do a quick switcheroo.

$ cp config.php config.tmp.php
$ svn update && mv config.tmp.php config.php


Leave a Reply