gitignore interpretation differs between ripgrep and Git #2800
-
I encountered an odd gitignore pattern that produced confusing (to me) results. The project in question has Here's a reproduction: ❯ git init
Initialized empty Git repository in /tmp/test/.git/
❯ echo '!*/' > .gitignore
❯ git add .gitignore
❯ git commit -m 'Add .gitignore'
[main (root-commit) 8a7ab23] Add .gitignore
1 file changed, 1 insertion(+)
create mode 100644 .gitignore
❯ touch .git/foo
❯ touch bar
❯ git status --short
?? bar
❯ rg --files
bar
.git/foo
.git/MERGE_RR
.git/logs/refs/heads/main
.git/logs/HEAD
.git/COMMIT_EDITMSG
.git/index
.git/objects/8a/7ab236b5afedea2a9351e18462d2856fa1c093
.git/objects/12/205745ebfad629068edb2cbf7058d06e4e6c53
.git/objects/c0/ff3025c379cfe7d5b27a4f6340226c50d03448
.git/HEAD
.git/refs/heads/main
.git/config
.git/info/exclude
.git/hooks/update.sample
.git/hooks/sendemail-validate.sample
.git/hooks/push-to-checkout.sample
.git/hooks/prepare-commit-msg.sample
.git/hooks/pre-receive.sample
.git/hooks/pre-rebase.sample
.git/hooks/pre-push.sample
.git/hooks/pre-merge-commit.sample
.git/hooks/pre-commit.sample
.git/hooks/pre-applypatch.sample
.git/hooks/post-update.sample
.git/hooks/fsmonitor-watchman.sample
.git/hooks/commit-msg.sample
.git/hooks/applypatch-msg.sample
.git/description
❯ rg --files --debug 2>&1 > /dev/null | grep '\.git:'
rg: DEBUG|ignore::walk|crates/ignore/src/walk.rs:1802: whitelisting ./.git: Whitelist(IgnoreMatch(Gitignore(Glob { from: Some("./.gitignore"), original: "!*/", actual: "**/*", is_whitelist: true, is_only_dir: true })))
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It's expected. Add ripgrep just respects your gitignore as they are written. git on the other hand uses repository state to list tracked files. This ultimately produce different results, especially when files that are gitignored are checked into the repository. This is expected and there are no plans to change that. |
Beta Was this translation helpful? Give feedback.
It's expected. Add
.git
to.rgignore
to ignore it.ripgrep just respects your gitignore as they are written. git on the other hand uses repository state to list tracked files. This ultimately produce different results, especially when files that are gitignored are checked into the repository. This is expected and there are no plans to change that.