Reputation: 655
I'm using msysgit 1.9.4.
My .gitignore file, at the root of the repo, looks like this:
build/
a/b/
!a/c/d/e/**/build/
My intent is that, all build/ directories are ignored, unless they are subdirs (any depth) of a/c/d/e/. But a/c/d/e/f/build/ is still getting ignored by Git.
What am I missing here?
Upvotes: 15
Views: 4782
Reputation: 8718
For example: You have ignored the /node_modules/
folder.
But you want to add a single file which you need to patch.
This is the file to whitelist: /node_modules/x/y/z/file.js
Add the following TO THE END of your .gitignore file:
/**
!/node_modules
!/node_modules/x
!/node_modules/x/y
!/node_modules/x/y/z
!/node_modules/x/y/z/file.js
The first line (/**) is important - no idea how it works :-)
Upvotes: 0
Reputation: 1324228
The general rule of gitignore
is simple:
It is not possible to re-include a file if a parent directory of that file is excluded.
To exclude files (or all files) from a subfolder of an ignored folder build
, you need to exclude the folder first, then the files:
I have tested:
**/build/
a/b/
!a/c/d/e/**/build/ <== whitelist folder first
!a/c/d/e/**/build/** <== then the files
Upvotes: 9