RSS
 

Example of How to Ignore Files in Subversion

04 Jul

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"
/pre>

However, I still have one last step, as shown by the following "status" command:

<pre class="syntax bash">
$ 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
VN:F [1.9.3_1094]
Rating: 8.4/10 (5 votes cast)
VN:F [1.9.3_1094]
Rating: +4 (from 4 votes)
Example of How to Ignore Files in Subversion, 8.4 out of 10 based on 5 ratings
Retweet
 
 
  1. Michael

    November 5, 2009 at 11:49 am

    Hi Chovy,

    My understanding of the -F option of “svn propset” is that it still updates the svn properties for the target folder, which are then committed to repository. In other words, using the -F option doesn’t make my svn:ignore entries local, it just means it used a local file as input when setting the (global) properties.

    Is there something I’m missing? (Possibly your point altogether…)

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  2. chovy

    November 6, 2009 at 1:09 am

    Yeah, you might be :)

    My example is how to set an svn:ignore property and check it into the repository. The assumption here is that nobody really wants to see un-committed files under the ./template_c directory.

    VN:F [1.9.3_1094]
    Rating: 5.0/5 (1 vote cast)
    VN:F [1.9.3_1094]
    Rating: +1 (from 1 vote)
     
  3. dootzky

    December 7, 2009 at 3:43 am

    THANKS!! works great!

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  4. chovy

    December 19, 2009 at 1:14 am

    glad it worked for ya.

    VN:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VN:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  5. lucid

    May 20, 2010 at 4:43 am

    btw, just another note. you can’t ignore files that have been already committed. Well it didn’t work for me. it seems to only ignore new files. hmm maybe it’s just me

    VA:F [1.9.3_1094]
    Rating: 5.0/5 (1 vote cast)
    VA:F [1.9.3_1094]
    Rating: +1 (from 1 vote)
     
  6. chovy

    May 20, 2010 at 9:51 am

    Yes, that is true. It doesn’t make sense to ignore a file that svn already is aware of. The point of ignore is to skip svn completely. Usually this is used for ignoreing .log files that change frequently and aren’t imperative to the application or source code. Also temporary files, ie: cached templates, session files, and the like.

    VA:F [1.9.3_1094]
    Rating: 5.0/5 (1 vote cast)
    VA:F [1.9.3_1094]
    Rating: +1 (from 1 vote)
     
  7. chovy

    May 20, 2010 at 9:52 am

    @lucid — also, if you want to remove a file and then apply the ignore rule, you would have to run: $ svn rm ./path/to/file

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)