我使用npm启动了一个项目,添加了一些依赖项,然后初始化了存储库usign git init.
我希望node_modulesgit忽略该目录,所以我将其添加到.gitignore文件中.
的.gitignore
node_modules/
Run Code Online (Sandbox Code Playgroud)
当然因为node_modules之前添加过git init,它仍然被认为是要跟踪的目录.
所以我删除它,使用以下命令(如同类似问题所述)
git rm -r --cached .
git add .
git commit -m ".gitignore should now work"
Run Code Online (Sandbox Code Playgroud)
然后使用重新安装npm依赖项 npm install
在此之后,我希望node_modules最终忽略该目录.相反,如果我输入git status我
Untracked files:
(use "git add <file>..." to include in what will be committed)
node_modules/
Run Code Online (Sandbox Code Playgroud)
为什么?