git .gitignore 不会忽略目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22924633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.gitignore is not ignoring directories
提问by Hal Carleton
What I did:
我做了什么:
I think there were some weird configurations from the github gui that caused this issue and prevented me from being able to easily use git from command line or even git-bash.
我认为 github gui 中有一些奇怪的配置导致了这个问题,并阻止了我能够从命令行甚至 git-bash 轻松使用 git。
I ended up just uninstalling github and git then reinstalling just git for windows. I now have everything running off the command line(except ssh which I run from git-bash). Much easier and more reliable that the github gui.
我最终只是卸载了 github 和 git,然后只为 Windows 重新安装了 git。我现在可以从命令行运行所有内容(除了我从 git-bash 运行的 ssh)。比 github gui 更容易和更可靠。
Thanks to mu 無 for taking the time to try to figure this out. I didn't end up using his answer, but if I hadn't needed to do a reinstall of git it would have been what I needed to do.
感谢 mu 无花时间尝试解决这个问题。我最终没有使用他的回答,但是如果我不需要重新安装 git,这就是我需要做的。
I am using the github gui on my local machine. I just noticed that a commit I was about to make was going to update all of my recently update node modules. I set up my .gitignore to ignore the entire node_modules/
directory.
我在本地机器上使用 github gui。我刚刚注意到我即将进行的提交将更新我最近更新的所有节点模块。我将 .gitignore 设置为忽略整个node_modules/
目录。
I'm not sure what to do about this. All the file types I included in .gitignore were ignored. It's just the directories that it seems to ignore.
我不知道该怎么办。我在 .gitignore 中包含的所有文件类型都被忽略了。这只是它似乎忽略的目录。
Here is my .gitignore file:
这是我的 .gitignore 文件:
#################
## Sublime Text
#################
*.sublime-project
*.sublime-workspace
#################
## Images
#################
*.jpg
*.jpeg
*.png
*.gif
*.psd
*.ai
#################
## Windows detritus
#################
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#################
## Directories
#################
dev/
cms/core/config/
node_modules/
回答by u1860929
Since the node_modules
directory is already tracked as part of the repository, the .gitignore
rule will not apply to it.
由于该node_modules
目录已作为存储库的一部分进行跟踪,因此该.gitignore
规则将不适用于它。
You need to untrack the directory from git using
您需要使用 git 从 git 中取消跟踪目录
git rm -r --cached node_modules
git commit -m "removing node_modules"
You can run the above 2 in git-bash
.
您可以在git-bash
.
After this, the .gitignore
rule will ignore the directory away.
在此之后,.gitignore
规则将忽略该目录。
Note that this will remove the directory node_modules
from your other repos once you pull the changes in. Only the original repo where you made that commit will still have the node_modules
folder there.
请注意,node_modules
一旦您拉入更改,这将从您的其他存储库中删除该目录。只有您进行该提交的原始存储库仍将在node_modules
那里保留该文件夹。
回答by Matthew M
If the files are already tracked the .gitignore
file will not override this. You will need to use git rm --cached <files>
如果文件已经被跟踪,.gitignore
文件将不会覆盖它。您将需要使用git rm --cached <files>
See the full details on git rm
at
https://www.kernel.org/pub/software/scm/git/docs/git-rm.htmlI ran into this once or twice myself early on with git and it was not quite what I expected either.
查看全部细节git rm
在
https://www.kernel.org/pub/software/scm/git/docs/git-rm.html我就遇到了这个一次或两次,我早早就使用Git,这是不完全是我预计。
回答by Scotty.NET
Similar to Zach, I also used echo "node_modules/" >> .gitignore
.
与 Zach 类似,我也使用了echo "node_modules/" >> .gitignore
.
The problem was it had created the file with encoding UCS-2 LE BOM
. Using notepad++I changed the encoding to UTF-8 and voila - node_modules is now ignored.
问题是它创建了带有 encoding 的文件UCS-2 LE BOM
。使用记事本++,我将编码更改为 UTF-8,瞧 - node_modules 现在被忽略了。
回答by prosti
If you work with node projects, I like this .gitignore
:
如果您使用节点项目,我喜欢这样.gitignore
:
# See http://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
node_modules
# testing
coverage
# production
build
# misc
.DS_Store
.env
npm-debug.log
回答by Zach Dahl
I had this problem. Somehow when I generated the file (using echo "node_modules" > .gitignore) it had inserted a garbage character at the beginning of the file (I blame powershell).
我有这个问题。不知何故,当我生成文件(使用 echo "node_modules" > .gitignore)时,它在文件的开头插入了一个垃圾字符(我责怪 powershell)。
So, if you run into this problem try deleting your .gitignore and starting over.
因此,如果您遇到此问题,请尝试删除 .gitignore 并重新开始。