Skip to content

How to use ignore file from a child directory #1977

Answered by BurntSushi
mhanberg asked this question in Q&A
Discussion options

You must be logged in to vote

Yes. It should work. Consider this directory tree:

$ tree -a
.
├── p1
│   ├── foo.rs
│   ├── .gitignore
│   └── node_modules
│       └── foo.rs
└── p2
    ├── deps
    │   └── foo.rs
    ├── foo.rs
    └── .gitignore

With the contents of .gitignore:

$ cat p1/.gitignore
/node_modules
$ cat p2/.gitignore
/deps

Let's run rg --files to show what will be searched:

$ rg --files
p2/foo.rs
p1/foo.rs
p1/node_modules/foo.rs
p2/deps/foo.rs

But wait, why are the node_modules and deps files showing up? That's because neither p1 nor p2 are actually git repos. ripgrep only respects gitignore files inside git repos, and ripgrep detects git repos by the presence or absence of .git. So let's create that:

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@mhanberg
Comment options

@BurntSushi
Comment options

@mhanberg
Comment options

@BurntSushi
Comment options

Answer selected by mhanberg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants