Skip to content

Find in Files "files to include" override .gitignore #26574

Open

Description

@borekb

VSCode 1.12: I have a TypeScript project with a src folder and a .gitignore file containing this:

/src/**/*.js

If I search for something, it is OK with 'files to include' is empty:

image

but it is not OK if I scope the search:

image

While I'm searching only in some sup-tree of my project, all .gitignore rules should still be taken into account.

Activity

  1. added
    search
    on May 14, 2017
  2. roblourens commented on May 14, 2017

    @roblourens
    Member

    It seems like ripgrep will let include globs override entries in the gitignore file. I'm not sure whether that's expected or whether we can change that. But one workaround is to use ./src syntax in 'files to include'.

  3. added
    feature-request
    on Nov 21, 2017
  4. kompot commented on Feb 28, 2018

    @kompot

    ./src seems to be broken again - regardless of syntax put to files to include .gitignore is no longer respected by ripgrep. I'm pretty sure it worked before, maybe ripgrep API change?

  5. roblourens commented on Mar 7, 2018

    @roblourens
    Member

    Unfortunately that's because I changed it to not use gitignore files in parent directories which breaks that workaround.

  6. kompot commented on Feb 19, 2019

    @kompot

    This was working OK up to version 1.30.
    1.31 broke this.

  7. roblourens commented on Feb 19, 2019

    @roblourens
    Member

    Can you explain what you mean by "this"? This issue has been open for a long time.

  8. roblourens commented on Feb 19, 2019

    @roblourens
    Member

    Sorry I see, the workaround I mentioned above will not work anymore. The only suggestion I have right now is to add patterns to search.exclude as well. I'll have to figure out why ripgrep handles gitignore patterns differently.

  9. kompot commented on Feb 20, 2019

    @kompot

    Seems like it's discussed in this ripgrep issue
    BurntSushi/ripgrep#829

    UPD
    and there's even an unmerged PR
    BurntSushi/ripgrep#963

  10. roblourens commented on Feb 20, 2019

    @roblourens
    Member

    I can't tell whether that's the right issue or not. vscode does not invoke rg with a path argument, the ./ syntax is converted to glob patterns.

  11. kompot commented on Feb 20, 2019

    @kompot

    Right now I observe this bug/feature/behaviour both in vscode and in rg console output.

    I have a file at path front/build/1.html. It contains string xxx. Directory front/build is gitignored.

    rg xxx from project root finds nothing
    rg xxx -g "front/**/*" finds xxx

    same happens in vscode

    searching with files to include being empty finds nothing
    searching with ./front in files to include finds xxx

    As a proposal: maybe vscode should always search from root and filter with files to include afterwards in memory just for UI. More work but it's near instant with ripgrep anyway.

  12. roblourens commented on Feb 20, 2019

    @roblourens
    Member

    When searching a big repo, there can actually be a large perf gain by using ./ vs searching everything.

  13. roblourens commented on Oct 9, 2019

    @roblourens
    Member

    I am pretty sure BurntSushi/ripgrep#829 is the correct upstream issue for this.

  14. added
    upstream-issue-linked
    on Oct 9, 2019
  15. 20 remaining items

  16. tsheaff commented on Jun 8, 2025

    @tsheaff

    There have been similar comments above, but since we're in an AI world now, I figured I'd help the community with an AI-first solution that solved this for me (even tho it's not 100% robust to changes, it does solve the issue for me, and it can always be re-run again).

    1. Run find . -maxdepth 2 -name ".gitignore" | xargs cat to print out all the gitignores (change maxdepth if needed for your purposes)
    2. Run the following prompt in Claude:
    Here are all my gitignores for all shared repos
    
    -----
    INSERT ALL GITIGNORES HERE
    -----
    
    Here is my VSCode setting
    
    -----
    "search.exclude": {
        "**/node_modules": true,
        INSERT ANY OTHER EXISTING search.exlude VALUES HERE
    }
    -----
    
    Write a full version of search.exclude that'll exclude the all of the files that should be excluded by those gitignores, collectively. I don't want anything that should be gitignored to come back in VSCode search.
    

    Then replace the INSERT statements with the result of (1) and your own existing VSCode settings.

    This gives you a COMPLETE list of things to update the VSCode search.exclude setting with, and for me this fully solves the issue. Could turn this into an automated script with an LLM API call if you really find it getting out of date often. And if it doesn't work perfectly the first time, I'm sure a small tweak to the prompt would get it working reliabily.

    Hope it helps.

  17. mcandre commented on Jun 9, 2025

    @mcandre

    AI is garbage, 100% would not recommend.

    Fix VSCode's stock behavior.

  18. simon-id commented on Aug 20, 2025

    @simon-id
    Contributor

    I think this has been resolved in unreleased commits in ripgrep: BurntSushi/ripgrep@c2f1653

  19. simon-id commented on Sep 21, 2025

    @simon-id
    Contributor

    The fix has now be merged in ripgrep's master and should be released soon. Now I'm trying to convince the vscode team to update it here: #263124

  20. simon-id commented on Feb 4, 2026

    @simon-id
    Contributor

    So the issue to update ripgrep was closed because apparently a PR was merged to do so. But after cloning the main branch, I can still reproduce this bug. i.e.: for the same search query, i get waaay more results when specifying a subfolder search path, than when I search on the root folder, as the ignored files are not actually ignored when specifying a subpath.

    Image Image

    I'm not sure if i'm doing it wrong, i got the wrong branch without the fix, or something, or if the fix doesn't actually work. I'd appreciate if someone could try to reproduce this too, so we can know if it's actually fixed or not.

  21. Keavon commented on Feb 4, 2026

    @Keavon

    Yes, it has never been fixed in VS Code.

    Edit: but that was merged only 5 days ago, so I expect it will take until the next release for us. It does appear to finally update to ripgrep 15, from the dependencies I just checked through that were just updated.

  22. simon-id commented on Feb 4, 2026

    @simon-id
    Contributor

    Keavon Chambers (@Keavon) That's exactly what I just wrote, the PR to update ripgrep was merged, and thus I tried to repro the bug in the main branch, which should have the udpated ripgrep dependency with the upstream fix, and i sadly still manage to reproduce the bug :/
    Thus I ask if other people also reproduce the bug on the main branch, or if i did something wrong. I'm not sure what you're trying to say?

  23. hskrtich commented on Feb 4, 2026

    @hskrtich

    The ripgrep 15 change has just been included in an insider build of VS Code. So it may be a good idea to test to see if this is still an issue.

  24. webdevelukas commented on May 21, 2026

    @webdevelukas

    This is still an issue in VS Code Version 1.121

  25. simon-id commented on May 21, 2026

    @simon-id
    Contributor

    I'm also not seeing an improvement on this issue in recent versions of vscode :/

  26. mcandre commented on May 22, 2026

    @mcandre

    Keep the comments rolling in. Microsoft has a nasty habit of arbitrarily closing bug reports over time.

  27. clintonmead commented on Jun 5, 2026

    @clintonmead

    I'm finding this annoying too. Is this fundamentally a problem with ripgrep (i.e. it doesn't have an option to have this behaviour) to VSCode (as in ripgrep can achieve this but VSCode just isn't using the option)? Or is it that ripgrep didn't have this option and now does but VSCode isn't using the latest ripgrep version?

  28. domenicogemoli-kaiko commented on Sep 29, 2026

    @domenicogemoli-kaiko

    Still an issue

  29. thany commented on Nov 25, 2026

    @thany

    Even a simple wildcard like *.scss will make it ignore .gitignore files, even though both options to use .gitignore are enabled in the settings AND in the search panel.

    Adding a file inclusion filter can never cause it find more files than without it, since you're telling it to restrict, not broaden, the files to search through.

    It reminds me of those oldie-worldie search engines, where adding more search terms caused them to return more results, not fewer 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requestsearchupstream-issue-linked

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions