我使用npm启动了一个项目,添加了一些依赖项,然后初始化了存储库usign git init
。
我希望git忽略目录node_modules
,所以我将它添加到.gitignore
文件中。
的.gitignore
node_modules/
当然因为在node_modules
之前添加了git init
,它仍然被认为是一个跟踪的目录。
所以我删除它,使用以下命令(如同类似问题所述)
git rm -r --cached .
git add .
git commit -m ".gitignore should now work"
然后使用npm install
重新安装npm依赖项
在此之后,我希望最终忽略目录node_modules
。相反,如果我键入git status
我得到
Untracked files:
(use "git add <file>..." to include in what will be committed)
node_modules/
为什么?
在this question下,有许多可能的修复,因为.gitignore
文件无法正常工作。
在这种情况下,问题是(是).gitignore
文件的编码是UNICODE而不是ASCII
请尝试以下方法: