Skip to content


Subversion checkout URL

You can clone with
Download ZIP


problems with --ignore #385

cvlmtg opened this Issue · 28 comments

what's the format of the --ignore pattern? If I do

ag --ignore '*.min.js' time website/public/vendor/ | less

ag still looks into website/public/vendor/jquery-ui.min.js

I've tried also '.*\.min\.js', '.min.js$' etc with no results.
I'm on OSX 10.9 with ag compiled through homebrew.


Having the same problem… v0.21.0


I am having the same problem. Patterns from .agignore are not taking effect either... v0.21.0


Just hit this as well.


I hit this, and it looks like it's only when it's the filename that should match; if you can use a regex that matches part of the path to ignore (I know, not always possible) it will work ok. Just a possible work-around.

@iizukanao iizukanao referenced this issue from a commit in iizukanao/the_silver_searcher
@iizukanao iizukanao Fix behavior of glob patterns for ignores
Fixes #385

I'm having this problem too on version 0.22.0. It fails even when I don't use a wildcard and just have "js/foo.js" in my .gitignore.


I've hit this too. 0.21.0 is the latest homebrew offers.


This is still an issue in version 0.22.0.


Maybe a separate issue, but:

--ignore foo/bar does not work, --ignore foo works

--ignore is supposed to be an alias to --ignore-dir of ack, in which --ignore-dir foo/bar does work.

ag version 0.23.0

There have been a few patches which have addressed this but none have been commented upon by @ggreer. I think it is the most glaring flaw in ag just now and the underlying problem seems fairly simple.

Now there is a functioning test suite, I'd suggest someone makes a pull request with failing tests related to directory recursion and ignore files. Someone with a bit of time on their hands might be able to polish up my old patch dae7f6c to rebase off the current master and see whether it satisfies the tests.


Found a temporary workaround. If you duplicate your ignore patterns like so:

ag --ignore *.min.js --ignore */*.min.js time

ag will correctly ignore files in subdirectories. Without the */ prefix, it only ignores files in the current working directory. Same thing works in the .agignore.



*Update: * looks like this only works for one level of subdirectories. Files 2 or three levels deep are still searched. :crying_cat_face:


@joechrysler With the latest version, I have the same problem for *~.

I put *~ in ~/.agignore, but it does not work.
Thus I am now using


It is a workaround for me.


Dev Folder

ag --ignore 20* model ~/Development/App

is a failure.

Is there a working version of Ag where --ignore did work?

I have tried 0.22.0 and 0.23.0


I'm seeing this as well with versions 0.22.0 and 0.23.0 installed with Homebrew on OS X 10.9.3. Ag's ignore flag works for me within the current directory but does not work recursively as @joechrysler pointed out above.

To reproduce:

$ mkdir dir
$ echo "test" > file.c
$ echo "test" > dir/file.c
$ ag --ignore=*.c test

Regarding @cvlmtg's original question, syntactically Ag it is fairly flexible; all of the following work in the current directory:

$ ag --ignore=*.c main
$ ag --ignore '*.c' main
$ ag --ignore "*.c" main

Having the same issue, not working recursively in subdirectories.


Ran a git bisect, and it looks like this was introduced in 2cc28cc.

My test was ag -p .agignore needle pyproj/, where .agignore contained just "*.py".

It also looks like -p .agignore is required when the search path is not the current directory? Shouldn't .agignore be read from the current directory?

Thanks for ag! This is hands-down the fastest, non-indexed search tool I have seen.


@ggreer Please fix this.
Right now I have these to ignore ~, *## and *.pdf files.


For those looking for a workaround (besides verbose ignore files!), just run tag 0.20.0... not that hard!

For those looking to give back to this awesome project, have a look at 2cc28cc and see if you can spot the problem. Seriously, someone with an hour should be able to read through ignore.c and figure this out.

No worries, I am sure someone will come through on this! ag works beautifully on 0.20.0. Cheers from Berkeley.

@ggreer ggreer closed this in #401
@schmonz schmonz referenced this issue from a commit in schmonz/the_silver_searcher
@iizukanao iizukanao Fix behavior of glob patterns for ignores
Fixes #385

I'm having the same problem (ag version 0.25.0 here).


still busted with ag 0.2.7 IMHO.


As of version 0.28.0

$ ag -l -U --ignore '/doc/' '~r/./' elixir/*

$ ag -l -U --ignore '/doc/' '~r/./' elixir/

the * at the end of the PATH breaks the --ignore argument.


@eksperimental Two things:

  1. You put a forward slash at the start of your ignore pattern, which means, "Only ignore at the root level." This isn't causing a problem in your example, but it's worth noting.

  2. Ag doesn't see the star in the first example. Bash or zsh expansion is passing elixer/doc (among other paths) to ag. Ag doesn't ignore paths that are explicitly passed to it on the command line.


sorry @ggreer , i didn't understand No. 2
thanks for answering,
but it is still no clear what should be the pattern to ignore any result that contains a folder named doc ?
--ignore '.*/doc/.*'

if so, it is not working:

$ ag -U -l --ignore '.*/doc/.*' '~r/./' elixir

the only one that seems to work is:

$ ag -U -l --ignore 'doc/' '~r/./' elixir

which is wrong according to your definition above, because the path of the ignored files does not start with "doc/"



In the first example of your previous comment, you put a forward slash at the start of your ignore pattern. That is, the pattern started with /. If it starts with /, that means "ignore only in the current directory. If it ends in a /, that means "only match if it's a directory."


  • doc ignores any file or directory anywhere that is called "doc".

  • /doc ignores any file or directory in the root dir called "doc".

  • doc/ ignores any directory anywhere that's called "doc".

  • /doc/ ignores any directory in the root called "doc".

These examples are typical behavior for .gitignore and .hgignore. Ag isn't doing anything strange here.

Second point: If you run ag blah elxir, that's the same as cd elixer && ag blah. That means "doc" is in the root. An ignore pattern like .*/doc/.* will only match doc directories in a sub-directory. Actually, I'm not even sure that will match anything sane. Ignore patterns are fnmatch() patterns, not PCREs.


thanks @ggreer it is a bit more clear now.
I think you should put in the documentation what kind of pattern it expects,
seems you use the same word (PATTERN) do describe the search PATTERN (regex).
I searched the respository and there's not reference to fnmatch().

so answering myself.
$ag -U -l --ignore 'doc/' '~r/./' elixir/
is the right command.

thanks for creating ag, I use it every day I'm with the computer pretty much

@blackb1rd blackb1rd referenced this issue from a commit in blackb1rd/the_silver_searcher
@iizukanao iizukanao Fix behavior of glob patterns for ignores
Fixes #385


This still doesn't seem to be working, with ag version 0.30.0 (the latest available on Homebrew).

This is my .agignore file:


and yet ag -l includes files like client-app/bower_components/ember/ember.min.js. What's going on?

I notice that putting *.js in my .agignore (even with nothing else) prevents ag from examining such a file.


FYI. If an ignore pattern is set as '*.min.js' and the patch from #680 (by @epmatsw) is applied, the complaints about ag not ignoring .min.js files should be fixed. Example:

$ ls
jj.js  jj.min.js
$ ../ag  --ignore '*.min.js' -g 'js' -l

@decaff What is preventing #680 from being merged and released as part of ag?

I see lots of bugs (#413, #678 and this one #385) referencing this issue.


@shreevatsar I think the author is very busy. Just a guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.