.gitignore 忽略文件,即使没有规则指定它

.gitignore ignoring a file even though no rules specify it

这是我的 .gitignore 文件:

smarty/templates_c
config.codekit
components/**/styles/
components/**/js/
!components/root/js-dev/plugin/select2-4.0.3/dist/js/
!components/root/js-dev/plugin/chartjs/
.sass-cache/
/node_modules/
/dbv-parkrooau/
/pma-parkrooau/
count.php

因此,如果我在 components/foo/js-dev/main.js 中进行更改,那么 .gitignore 将跟踪其更改,并将其包含在我的存储库中;这很好。

但是,我有一个位于 components/theygo/js-dev/shoppingcart.js 的文件 - .gitignore 不会 跟踪对此文件的更改,原因超出我的理解。 components/theygo/js-dev/main.jscomponents/root/js-dev/main.js 一样工作正常,到目前为止我创建的所有其他 JavaScript 文件也是如此 - 只有这个文件,我不确定为什么。

如果我从 .gitignore 中删除 components/**/js/,它会跟踪文件,但也会跟踪 js 子目录中的所有文件,在 [=22= 内的任何目录内].

如果我在这一行中添加:

!components/theygo/js-dev/shoppingcart.js

它正确地跟踪文件。

有人可以解释为什么会这样吗?我可以做些什么来最好地解决这个问题,而不是添加一个肮脏的包含声明?

你有没有.gitignore sub-directories?
基于你的 .gitignore,我也尝试了确切的文件夹结构,这个文件将被正确跟踪

首先提交并推送所有当前更改。 然后你必须删除所有跟踪的文件并将它们添加回 使用以下命令

git rm -r --cached .
git add .
git commit -m ".gitignore is now working"