Gitignore 异常未添加到跟踪

Gitignore Exceptions Not Being Added to Tracking

我的 .gitignore 中有以下内容:

*.log
/bower_components/*
/node_modules
!/bower_components/v-accordion
!/node_modules/todomvc-app-css/*

我在安装这些组件后添加了最后两行,所以这可能是问题所在,但我无法判断。

无论哪种方式,我都想跟踪对这些目录的更改,因为我正在积极自定义它们并将其推向生产。

但是,我似乎无法 Git 追踪它们。
我做错了什么,我该如何解决?

编辑:

.gitignore 的较新版本:

*.log

/bower_components/**
!/bower_components/v-accordion/
!/bower_components/v-accordion/**

/bower_components/angular-bootstrap-calendar/
!/bower_components/angular-bootstrap-calendar/
!/bower_components/angular-bootstrap-calendar/**

/node_modules/
/node_modules/**
!/node_modules/todomvc-app-css/
!/node_modules/todomvc-app-css/**

However, I cannot seem to get Git to track them

只需检查一下:

git check-ignore -v -- node_modules/todomvc-app-css/afile

这将确认 .gitignore 中阻止您跟踪该文件的规则。

规则很简单:

It is not possible to re-include a file if a parent directory of that file is excluded.

在排除内容之前需要先排除文件夹:

*.log

/bower_components/**
!/bower_components/v-accordion/**/
!/bower_components/v-accordion/**

/node_modules/**
/node_modules/todomvc-app-css/**/
!/node_modules/todomvc-app-css/**