主页 > 开源代码  > 

git上传项目把node_modules也上传至仓库了,在文件.gitignore中忽略node_modules

git上传项目把node_modules也上传至仓库了,在文件.gitignore中忽略node_modules
前言

新建了一个vitepress 项目 但上传至github的时候不小心把node_modules 上传到仓库中了,于是我重新添加了 .gitignore 然后重新上传项目, 上次成功后却发现 node_modules 在仓库中依然存在

思考

这种情况可能是因为 Git 会继续跟踪已经被提交的文件,即使你在 .gitignore 中添加了 node_modules

解决 1.删除已经被 Git 跟踪的 node_modules 目录: git rm -r --cached node_modules 2.确保 .gitignore 文件已正确配置:

确保 .gitignore 中已经正确包含了 node_modules:

node_modules 3.重新提交: git add . git commit -m "Remove node_modules from version control" git push

这几步完成后,node_modules 就不会再出现在仓库中了。如果你再做一些修改并推送,Git 应该会忽略 node_modules 文件夹了。

标签:

git上传项目把node_modules也上传至仓库了,在文件.gitignore中忽略node_modules由讯客互联开源代码栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“git上传项目把node_modules也上传至仓库了,在文件.gitignore中忽略node_modules