is it possible to ignore .gitignore rules in subdirectory?
GitGit Problem Overview
I want to ignore all of .gitignore rules in subdirectory except .gitignore rules in root.
for example)
I have already .gitignore
file in a directory structure /a
.
And also have .gitignore
file in /a/b
. Assume /a
have a.txt
b.txt
files.
/a/b
has .config
file. .gitignore
defines .config
in /a/b
.
.config
file will be ignored by .gitignore
in /a/b
.
But I really want to track .config
file by ignoring rules of .gitignore
in subdirectory.
Is it possible?
Thanks in advance
Git Solutions
Solution 1 - Git
Your question isn't too clear, but if there are some subdirectories where you want different gitignore rules, you can just create a new .gitignore in that directory.
Say you have:
project/.gitignore project/stuff/.gitignoreThe .gitignore in stuff/ will override the .gitignore in the root directory.
git help gitignore
or man gitignore
has quite a bit more information about what's possible.
Solution 2 - Git
Lets say you want to include node_modules
in your repository, but some module down the line has .gitignore
of its own. You can negate the rules by adding the following to your root .gitignore
file:
# Make sure to include everything in node_modules.
!node_modules/**
Solution 3 - Git
The key to the problem here is that a parent directory is excluded. From $ man gitignore
:
> 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.
Here's how I've gotten it to work. Given:
/a/...
/b/foo
/c/...
/.gitignore
:
/*
!/b
Then /b/foo
will show up as included files while everything in /a
and /c
will be excluded. The trade off is that you have to do add a negation for all of the parents of any directory in which you want to include files.
Solution 4 - Git
As far as i know there's no way to do it. As the local .gitignore will overwrite the root ginignore My workaround is adding manually.
git add --force [ your file and folder]