从 .gitignore 不起作用的跟踪中排除

exclude from tracking with .gitignore not working

我正在尝试删除 "js" 文件夹中的所有文件以免被跟踪。

这是我的 .gitignore:

# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp


# dependencies

# IDEs and editors
/.idea

# misc
/.sass-cache
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
testem.log
/typings

# e2e
/e2e/*.js
/e2e/*.map

# js
js/


#System Files
.DS_Store

node_modules/
bower_components/
.sass-cache/
images/
app/test/reportscreenshots/
app/test/report/

请注意 js/ 它不会删除该文件夹中的文件以防止被跟踪。这是我的文件夹结构:

为什么我的 .gitignore 不排除 "js" 文件夹中的文件被跟踪?

如果文件夹之前已经被跟踪,将其添加到 .gitignore 不会取消跟踪。

您还需要从 git 存储库中删除 file/directory

git rm --cached -r mydirectory

--cached 会将其从 git 存储库中删除,但不会从服务器中删除。来自 this Whosebug question

之后,如果您git status,您将在状态中看到已删除的文件夹。您需要提交删除。