使用.gitignore忽略node_modules [英] Ignoring node_modules using .gitignore

查看:1079
本文介绍了使用.gitignore忽略node_modules的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用npm启动了一个项目,添加了一些依赖项,然后初始化存储库usign git init.

I started a project using npm, added a few dependencies and then initialized the repository usign git init.

我希望git忽略目录node_modules,因此我将其添加到.gitignore文件中.

I wanted the directory node_modules to be ignored by git, so I added it to the .gitignore file like so.

.gitignore

.gitignore

node_modules/

当然,由于node_modules是在git init之前添加的,因此仍被视为要跟踪的目录.

Of course because node_modules was added before git init, it is still recognized as a directory to track.

所以我删除了它,使用了以下命令(针对类似问题的建议)

So I deleted it, used the following commands (as suggesed for similar problems)

git rm -r --cached .
git add .
git commit -m ".gitignore should now work"

然后使用npm install

此后,我希望目录node_modules最终被忽略. 相反,如果我键入git status我会得到

After this I expect to have the directory node_modules to be finally ignored. Instead if I type git status I get

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    node_modules/

为什么?

推荐答案

此问题.gitignore文件无法正常运行有许多可能的修复方法.

Under this question there are many possible fixes for a .gitignore file not properly working.

在这种情况下,问题是.gitignore文件的编码是UNICODE而不是ASCII

In this case the problem is (was) that the .gitignore file's encoding was UNICODE instead of ASCII

这篇关于使用.gitignore忽略node_modules的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆