Consider this dummy static site structure:
$ mkdir -p docs/_build/ $ echo "<h1>hello</h1>" > docs/_build/index.html $ echo "# hello" > docs/index.md
ripgrep search for “hello” matches
$ rg hello docs/index.md 1:# hello docs/_build/index.html 1:<h1>hello</h1>
Suppose we want to ignore generated HTML files in
docs/_build/. We could add
docs/_build/ to a
$ echo "docs/_build/" > .gitignore
and searches ignore that folder:
$ rg hello docs/index.md 1:# hello
But explicitly searching the
docs folder matches files that we want ignored:
$ rg hello docs/ docs/_build/index.html 1:<h1>hello</h1> docs/index.md 1:# hello
Paths specified explicitly on the command line override glob and ignore rules.
which, in practice, seems to mean that the
.gitignore rules are applied
against filepaths relative to the filepath argument.
So in the above example, we can get the behaviour we want by changing the
.gitignore rule to
$ echo "**/_build/" > .gitignore $ rg hello docs/ docs/index.md 1:# hello
For a deeper discussion, see this ticket.