Unversioning (ignoring) a file in SVN

Unversioning (ignoring) a file in SVN

Last updated:
Table of Contents

Even though 99% of the time we want to keep the development version and the production version in synch, every now and then we want to have, for example, a config file that shouldn't be synched when we update the production version with new code.

Say you have a file name config.php which has specific configurations depending on whether it's on you development server or the production server.

If you don't unversion or ignore it, then every time you update your production server, the production-specific file version would get overwritten.

make a copy, delete old file from repo, rename the copy back to original name

  • cd into your development working directory and make a copy of the file:

    $ cp config.php config.php.unv
    
  • delete the original file:

    $ svn delete config.php
    $ svn commit
    
  • change the copied file's name back to the original:

    $ mv config.php.unv config.php
    
  • commit:

    $ svn commit
    

delete file from repo but keep local copy

  • in the development version, delete the file from the repo but keep it in the local(working) directory:

    $ svn rm --keep-local config.php
    $ svn commit
    
  • then log into your production version and create a copy of the config file:

    $ cp config.php config.php.tmp
    
  • then update the working directory (config.php will get deleted)

    $ svn update
    
  • and now re-name the copy back to the original name

    $ mv config.php.tmp config.php
    

done. Now SVN will behave as if it never knew the file. In other words, you can modify it and then update and/or commit your project and local changes to this file won't get overwritten.

svn propset svn:ignore

this is useful if you want to keep files that you don't want versioned (like those you have unversioned using the above approaches) from appearing in svn status output.

Suppose you have a directory called your_project_name/runtime which you don't want versioned, but it shows up everytime you do svn status:

  • cd to your project

    $ cd your_project_name
    
  • once in your_project_name, ignore runtime child directory:

    $ svn propset svn:ignore runtime .