忽略子目录中的 gitignore 文件

ignore gitignore files in subdirectories

这是我"root"的内容。git忽略

# exclude everything ...
*
# ...except
!/.gitignore
!*/
!/modules/wp-azth/**

问题是,在 modules 文件夹下,我有很多第三方模块,里面有一个 .gitignore 文件。

使用上面的规则,所有第三方模块文件夹都会被忽略,但它们的 .gitignore 文件不会(我当然不需要它)

有没有办法忽略 .git忽略被忽略子文件夹中的文件?也许 .git/config 可以用于此?

(我认为这是 git 的不良行为,即使他们被忽略了也会考虑他们)

UPDATE:似乎缺少 git,它允许忽略的文件夹 "arbitrary" 取消忽略自身具有 !.git git忽略文件中的忽略规则(由任何人)放置在忽略的子目录中。 忽略的文件夹通常可能包含动态文件、临时文件或第三方文件(缓存、临时文件、插件等)...因此 git 允许仅使用简单的 !.gitignore as rule 来创建不需要的行为在子目录中。

git gui screenshot

*.git忽略会起作用,但是 git 仍会跟踪。git忽略它已经在跟踪的文件


这两个命令之间的唯一区别是 运行 是我将 *.gitignore(通过您在中间看到的命令)添加到我的根级别 .gitignore 文件。


An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again.

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

意味着中间层 .gitignore 文件中可能包含 !*.gitignore,这可能会扰乱更高层的声明。

问题是 /modules 目录中的 .gitignore 个文件:

git check-ignore -v -n /modules/TC-JSON-API/storage/app/.gitignore returns: /modules/TC-JSON-API/storage/app/.gitignore:2:!.gitignore /modules/TC-JSON-API/storage/app/.gitignore

当时的解决方案是将 /modules/* 添加到我的 .gitignore:

# exclude everything ...
*
# ...except
!/.gitignore
!*/
!/modules/wp-azth/**

成为

# exclude everything ...
*
modules/*
# ...except
!/.gitignore
!*/
!/modules/wp-azth/**

我不明白为什么 git 需要这种 "specification" ...没有那个规则。git被忽略文件夹的忽略文件在 processed/listed犯罪。不过现在可以了。