Best practice to search for file names recursively respecting .gitignore? #1589
-
When searching for file names recursively like this when I want to find all index.js files:
Which flags can I set to make it respect my .gitignore which ignores folders like the Using ripgrep v12.1.0 on macOS Catalina. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You cannot cause explicit positional parameters like you've provided to be ignored by The way to work around this is to express your globs not to your shell, but to ripgrep itself. Here's an example:
The last example is the key. It says, "search the current directory recursively, with smart filtering, but only search files named |
Beta Was this translation helpful? Give feedback.
You cannot cause explicit positional parameters like you've provided to be ignored by
.gitignore
. This is an intentional design decision. In particular, ripgrep does not see**/index.js
. It sees the expansion of**/index.js
to every individual matching file by your shell. Therefore, ripgrep cannot differentiate betweenrg foo/index.js
andrg **/index.js
. They are literally exactly the same. Thus, if someone ranrg foo/index.js
andfoo/index.js
was in their.ignore
and ripgrep respected ignore files for positional parameters, thenrg foo/index.js
would not search anything. This would be highly unexpected, but does unfortunately lead to these sorts of cases where you want that ignore filter…