简体   繁体   English

如何将文件夹添加到 .gitignore

[英]How to add a folder to the .gitignore

Maybe my Googling skills are lacking but this seems like a question that should give me back thousands of hits and yet, I can't find a straight answer.也许我缺乏谷歌搜索技能,但这似乎是一个应该给我带来数千次点击的问题,然而,我找不到直接的答案。

Simple as this:就这么简单:

I do constant pushes to github to share with a remote developer.我不断推送到 github 以与远程开发人员共享。 We both have npm and bower installed.我们都安装了npmbower No need to push these huge folders to github all the time.无需一直将这些庞大的文件夹推送到 github。 My node_modules are ignored.我的node_modules被忽略。 But I can't seem to get gitignore to ignore my bower_components folder但我似乎无法让gitignore忽略我的bower_components文件夹

I'm not too savvy on cmd, I barely scratch the surface so if you ar going to suggest that, please don't assume I know what you are talking about.我对 cmd 不太了解,我几乎没有触及表面,所以如果你打算建议,请不要假设我知道你在说什么。 Otherwise if it is as easy as adding it to the file itself using an IDE, well, I did that and no cigar.否则,如果它像使用 IDE 将它添加到文件本身一样简单,那么,我做到了,没有雪茄。 Here is my .gtignore file for your review这是我的 .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

Am I missing anything?我错过了什么吗? How do I make the bower_components ignored?如何使 bower_components 被忽略?

Thank you谢谢

If you want to ignore folder, you need a trailing slash:如果你想忽略文件夹,你需要一个斜杠:

bower_components/

Then check if the rule apply with git check-ignore -v (the -v is important if you want to see the exact .gitignore file and line which causes a file to be ignored)然后使用git check-ignore -v规则是否适用(如果您想查看导致文件被忽略的确切.gitignore文件和行, -v很重要)

git check-ignore -v -- bower_components/afile

If that does not apply, then remove the content of that folder from the history of that repo:如果这不适用,则从该存储库的历史记录中删除该文件夹的内容:

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

Then the .gitignore rule will take effect immediatly.然后.gitignore规则将立即生效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM