Search code examples
gitignore

Ignore a specific file in resource directory


This is my .gitignore file:

HELP.md
tmp/
target/
!**/src/main/**
!**/src/test/**

How can I exclude only this file:

src/main/resources/application.properties

Thank you


Solution

  • It should be fairly easy:

    HELP.md
    tmp/
    target/
    !**/src/main/**
    !**/src/test/**
    src/main/resources/application.properties
    

    should work.

    In case it doesn't, as it appears to be your case1, git allows you to ignore files, but remember this is a local setting and it will not be pushed to any other repository: go to .git/info/exclude and edit the file. It works like .gitignore.

    Also remember: .gitignore has an higher priority on your info/exclude (source).


    1. this might be due to the fact that you have multiple .gitignore files in your directory, and thus there is overmatching of patterns.