问题描述
我使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!