开发者

is it possible to ignore .gitignore rules in subdirectory?

开发者 https://www.devze.com 2023-01-16 11:59 出处:网络
I want to ignore all of .gitignore rules in subdirectory except .gitignore rules in root. for example:

I want to ignore all of .gitignore rules in subdirectory except .gitignore rules in root.

for example: I already have .gitignore file in a directory structure /a.

And also have .gitignore file in /a/b. Assume /a has a.txt and b.txt files.

/a/b has .config file. .gitig开发者_如何学Pythonnore 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?


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/.gitignore

The .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.


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/**


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.


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]
0

精彩评论

暂无评论...
验证码 换一张
取 消