0

Ive been trying to understand git pattern format in order to not ignore certain common directories inside node_modules

I have more than 20 directories all of them share the same three chars, I am trying to figure out a pattern to exclude these dir's from gitignore

example

 node_modules
 |
 |apifoo
 |apibar
 |apix
 |..
 |..

.

Suhayb
  • 3,163
  • 3
  • 23
  • 30
  • 1
    Possible duplicate of [How do gitignore exclusion rules actually work?](https://stackoverflow.com/questions/3001888/how-do-gitignore-exclusion-rules-actually-work) – ochs.tobi Apr 24 '18 at 06:11
  • Read [this answer](https://stackoverflow.com/a/44568924/4265352) on a similar question. – axiac Apr 24 '18 at 06:17
  • You should ignore `node_modules` completely. Why would you track its content? – axiac Apr 24 '18 at 06:17
  • @axiac wired project, where controllers are inside node_modules as npm packages, cant modify the packages since they are private. – Suhayb Apr 24 '18 at 06:31

2 Answers2

1

https://git-scm.com/docs/gitignore

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "!important!.txt".

so something like !node_modules/api*

Markus Mikkolainen
  • 3,397
  • 18
  • 21
0

Avoid excluding node_modules as directory, instead exclude all it's files! since excluding a directory as @markus said will not let git pay attention to any rule inside that directory.

excluding node_modules be like node_modules/ which is not what you want, in your case you wanna tell git: please exclude all files inside node_modules dir not node_modules it self and this could be achieved by node_modules/* then add a negation to include any dir starts with api by !/node_modules/apihawk*/

Suhayb
  • 3,163
  • 3
  • 23
  • 30