Search code examples
gitgitignore

Include generally excluded file from specific folder


In my project, I have generated files Widget.js in project subfolders, so I git-ignore them with this rule:

widgets/*/Widget.js

so it ignores files like:

  • widgets/ignore_1/Widget.js
  • widgets/ignore_2/Widget.js

But now, in one specific folder, I want to include this file to repository. E.g.: file

  • widgets/include_1/Widget.js

should be included.

Is there any possibility to set the rules as I need?


Solution

  • Use ! to add this file again https://git-scm.com/docs/gitignore#_pattern_format.

    Just add

    !widgets/include_1/Widget.js
    

    after

     widgets/*/Widget.js