Comments (8)
This is correct behavior. From the man page:
The precedence of ignore rules is as follows, with later items overriding earlier items:
• Files given by --ignore-file.
• Global gitignore rules, e.g., from $HOME/.config/git/ignore.
• Local rules from .git/info/exclude.
• Rules from .gitignore.
• Rules from .ignore.
• Rules from .rgignore.
In other words, --ignore-file
has the lowest precedence and is overruled by your .gitignore
. The whitelist rule in .ignore
works because .ignore
specifically has higher precedence.
The docs for --ignore-file
appear misleading or perhaps even wrong:
--ignore-file=PATH
Specifies a path to one or more gitignore formatted rules files. These patterns are applied after the patterns found in
.gitignore, .rgignore and .ignore are applied and are matched relative to the current working directory. Multiple addi‐
tional ignore files can be specified by using this flag repeatedly. When specifying multiple ignore files, earlier files
have lower precedence than later files.
If you are looking for a way to include or exclude files and directories directly on the command line, then use -g/--glob
instead.
This should be rephrased to say that they have lower precedence than rules from other ignore files.
from ripgrep.
OK, make sense.
Is there a way to provide a global override file so ?
Main use case: I have some personal files which I ignore globally using a global git ignore (let's say .envrc
or .mise.toml
) that I know I always want to find in search results (this is why I have !.mise.toml
and !.envrc
in my ~/.config/search.ignore
)
Ideally, to make everyone happy, there should be both:
- a
--ignore-file-override
parameter or equivalent to be able to specify on-demand - a
$RG_IGNORE_FILE_OVERRIDE
environment variable to be able to specify once globally or by environment
If there is no such possibility, would you accept a pull-request adding it (it might take time, I'm no rust expert, still learning) ?
from ripgrep.
Sure, you could create a /.rgignore
since any .rgignore
file has precedence over all other .gitignore
files, for example. ripgrep will ascend parent directories to find ignore files.
Otherwise, no, I'm not accepting any major changes to how ignore rules work in ripgrep right now. Not until the system has been re-thought and probably redesigned.
from ripgrep.
Too bad, one .ignore
or .rgignore
by repository doesn't really scale because I have a huge amount of repositories to handle (I started with that and then submitted the issue when I realized the amount of file I have to create, a lifetime of projects history, each one having a combination of multiple files or directories I gitignored but need to match using rg).
I'll wait for the redesign. Thanks for the quick and precise answers !
from ripgrep.
You don't need to put a .rgignore
in each repository. I'm not sure where you got that from. You only need to put it in a shared parent directory. Hence the suggestion to use /.rgignore
. That's /
, the root of your file system. Not the root of each project directory. Of course, it doesn't have to be in the root of your file system. If all your repos are in ~/clones
, then you could put it at ~/clones/.rgignore
.
from ripgrep.
You only need to put it in a shared parent directory.
Oh, that will do it !! Thanks for the tip, I wasn't aware that parent files are processed ! 🙏🏼
Edit: working just fine, solved my issue !
I'm not sure where you got that from.
Hard to answer. This has been a long journey (not) finding this right info:
The rg --help
section about --ignore-file
only talks about the current working directory for those files. And this is also the one that made me think there was a bug given it says clearly These patterns are applied after the patterns found in .gitignore...
--ignore-file=PATH
Specifies a path to one or more gitignore formatted rules files. These
patterns are applied after the patterns found in .gitignore, .rgignore
and .ignore are applied and are matched relative to the current working
directory. Multiple additional ignore files can be specified by using
this flag repeatedly. When specifying multiple ignore files, earlier
files have lower precedence than later files.
Then I found the User Guide dedicated section referenced in the README, but it only talks about git specific ignore files (including only globals from core.excludesFile
and current dir .ignore
that override, no reference to --ignore-file
nor to parent files).
So I read comments from all the PRs on the topics trying to find data and one was saying that only the current repository .(rg|git|)ignore
files are handled (and that rg
is converging toward using .ignore
) as well as the "global ignore files" but without details on what it means.
I wasn't even aware that there is a man
page, it's not said once in the README, the User guide or the --help
(or more precisely I missed it if this is the case).
So clearly a documentation issue and I might submit PR clarifying that between the readme, the help, the user guide and the manpage. Would you accept such pull request ?
from ripgrep.
Hard to answer. This has been a long journey (not) finding this right info
Ah yeah, sorry, I was referencing my prior comment where I suggested /.rgignore
. :-)
Otherwise I agree that the whole UX around ignore rules is sub-optimal. There are also legitimate bugs with its implementation. So it's all a bit of a mess unfortunately, but mostly works.
from ripgrep.
So clearly a documentation issue and I might submit PR clarifying that between the readme, the help, the user guide and the manpage. Would you accept such pull request ?
Yes I'd be happy to try and work with you on that. Thank you!
from ripgrep.
Related Issues (20)
- Incorrect application of ignore rule with single glob in nested HOT 1
- Since nightly-2024-02-06 , could not compile with --features 'simd-accel' HOT 4
- rg allocates too much memory with: `rg --files --ignore-file ~/.ultimate-gitignore` HOT 2
- Repo HOT 1
- When i using rg to find file's type of rust, it doesn't work. HOT 1
- Typo in help description for --vimgrep option: "im" instead of "in" HOT 1
- rg spins in a nanosleep loop when one thread is blocked on a fifo
- [ignore] Fallback to use git check-ignore or support hook iteration HOT 3
- [feature request] Context up to a matching pattern instead of by fixed number of lines HOT 1
- ignore: WalkBuilder::build_parallel() example does not compile HOT 1
- FR: sort results by count HOT 1
- ripgrep does not properly apply ignore rules from .gitignore in parent directory
- global ignore / ripgreprc shell parameter expansion HOT 2
- unicode uppercase HOT 3
- .gitignore rule is matched incorrectly while in a subdir
- Adjacent replaced multiline matches result in wrong line numbers HOT 4
- Feature Request (globset): Expose `MatchStrategy` HOT 6
- Support decompression flags / smart use of zstd --long HOT 1
- Add `Select-String`/`sls` to the benchsuite HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ripgrep.