这是我的“root”.gitignore 的内容
# exclude everything ...
*
# ...except
!/.gitignore
!*/
!/modules/wp-azth/**
问题是,在 modules 文件夹下,我有很多第三方模块,里面有一个 .gitignore 文件。
使用上面的规则,所有第三方模块文件夹都会被忽略,但它们的 .gitignore 文件不会(我当然不需要它)
有没有办法忽略被忽略的子文件夹中的 .gitignore 文件?也许 .git/config 可以用于此?
(我认为这是 git 的不良行为,即使它们被忽略也会考虑它们)
更新:似乎缺少 git,它允许被忽略的文件夹“任意”取消忽略自身,在被忽略的子目录中放置(由任何人)的 gitignore 文件中有 !.gitignore 规则。 忽略的文件夹通常可能包含动态文件、临时文件或第 3 方文件(缓存、临时文件、插件等)...因此 git 允许仅使用简单的 !.gitignore 作为子目录内的规则来创建不需要的行为。
最佳答案
*.gitignore 可以工作,但是 git 仍然会跟踪它已经跟踪的 .gitignore 文件
正在运行的两个命令之间的唯一区别是我将 *.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,这可能会扰乱更高级别的声明。
关于git - 忽略子目录中的 gitignore 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34553193/