1

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?

1615903
  • 32,635
  • 12
  • 70
  • 99
ZdenekJ.
  • 43
  • 3

3 Answers3

2

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
Alex Lyalka
  • 1,484
  • 8
  • 13
0

First unignore the direcory and then the file in your .gitignore:

widgets/*/Widget.js
!widgets/include_1/
!widgets/include_1/Widget.js

See https://stackoverflow.com/a/5285539/7976758

phd
  • 82,685
  • 13
  • 120
  • 165
0

If it is only the single file, it might be easier to just force add the file and not touch the .gitignore rules at all. .gitignore only works on untracked files, so once you add the file once, it will remain tracked:

git add -f widgets/include_1/Widget.js

Documentation:

-f

--force

Allow adding otherwise ignored files.

1615903
  • 32,635
  • 12
  • 70
  • 99