Example of How to Ignore Files in Subversion
Brief example of how to ignore files in subversion. Great for those pesky session, cached files, or logs that are constantly changing and are not necessary to “version”.
Have you ever had those pesky little files constantly telling you they’ve been modified? …you couldn’t care less about “commiting” them into the subversion repository every time, right? — log files, session data, temporary caches are all great examples of things that should probably be ignored and forgotten.
Ignoring locally modified files in subversion is quite easy, once you get the hang of it.
I struggled a bit with the example from the SVN book. Mainly because I was unsure where to actually set my property.
I’m writing an application with Smarty and PHP and have several temporary files created in my development environment and wanted to simply “ignore” them all so they do not keep showing up when I run an “svn status” command…
$ touch ./template_c/foo
$ svn st
? template_c/foo
Everything under “template_c” should be ignored by subversion, I do not want to version temporary cache files of templates created with new requests.
Here’s the quick and easy way to get it done…
$ cd ~/trunk
$ svn propset svn:ignore '*' ./template_c/
First, I change directory into the trunk (or parent of the directory I want to ignore).
Then I simply set an svn property “svn:ignore”, which takes 2 property arguments: the pattern of the file to ignore, and the directory path to apply it to.
In other words, I am telling svn to set the property “svn:ignore” to ignore all files “*” under the sub-directory “./template_c”.
If I wanted to ignore only smarty template php files, I would’ve used something like:
$ svn propset svn:ignore '*.tpl.php' ./template_c/
#ignores files such as "foo.tpl.php"
However, I still have one last step, as shown by the following “status” command:
$ svn st
M .
M template_c
…commit the new property for the current directory (this property will apply to all svn users once committed).
$ svn ci -m 'ignore smarty template caches' .
If you want to only apply the change to your local repository, then look into the ‘-F’ option to “svn propset” to specify a local file with a list of file patterns to ignore. This way, developers can add/remove entries from their own local copy if they wish.
One last trick — if I really want to see what is in the ignored directory, I just run the command with the “–no-ignore” option:
$ svn st --no-ignore
I template_c/foo



















