使用 .gitignore 排除跟踪不起作用

Ben*_*ins 0 git gitignore

我试图从跟踪中删除“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/
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述

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

Jac*_*Goh 8

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

您还需要从 git 存储库中删除文件/目录

git rm --cached -r mydirectory

--cached将从 gitrepo 中删除它,但不会从服务器中删除它。来自这个 StackOverflow 问题

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