如何将文件夹添加到 .gitignore

How to add a folder to the .gitignore

也许我的谷歌搜索技能不够,但这似乎是一个应该给我返回数千次点击的问题,但我找不到直接的答案。

就这么简单:

我不断推送 github 以与远程开发人员共享。我们都安装了 npmbower。无需一直将这些巨大的文件夹推送到 github。我的 node_modules 被忽略了。但我似乎无法让 gitignore 忽略我的 bower_components 文件夹

我对 cmd 不是很了解,我只是浅尝辄止,所以如果您要提出建议,请不要以为我知道您在说什么。否则,如果它就像使用 IDE 将它添加到文件本身一样简单,那么,我做到了并且没有雪茄。这是我的 .gtignore 文件供您查看

# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-    task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages
bower_components

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

我错过了什么吗?如何让 bower_components 被忽略?

谢谢

如果你想忽略文件夹,你需要一个尾部斜线:

bower_components/

然后检查规则是否适用于 git check-ignore -v(如果您想查看确切的 .gitignore 文件和导致文件被忽略的行,-v 很重要)

git check-ignore -v -- bower_components/afile

如果不适用,则从该存储库的历史记录中删除该文件夹的内容:

git rm --cached -r -- bower_components/
git add .
git commit -m "Remove bower_components folder"

那么.gitignore规则将立即生效