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 文件夹了。

相关推荐
Elasticsearch6 小时前
为上下文工程构建高效的数据库检索工具
elasticsearch
武子康6 小时前
大数据-243 离线数仓 - 实战电商核心交易增量导入(DataX - HDFS - Hive 分区
大数据·后端·apache hive
今日无bug7 小时前
Git 提交:用全栈技术打造智能 Commit Message 生成器
git·全栈
明月_清风9 小时前
拒绝盲目 Git:VS Code 神级插件 GitLens 的 9 个进效杀手锏
前端·git
代码匠心2 天前
从零开始学Flink:Flink SQL四大Join解析
大数据·flink·flink sql·大数据处理
goodspeed3 天前
Git Worktree:多分支并行开发的利器
git·github
武子康3 天前
大数据-242 离线数仓 - DataX 实战:MySQL 全量/增量导入 HDFS + Hive 分区(离线数仓 ODS
大数据·后端·apache hive
Elasticsearch3 天前
需要知道某个同义词是否实际匹配了你的 Elasticsearch 查询吗?
elasticsearch
SelectDB4 天前
易车 × Apache Doris:构建湖仓一体新架构,加速 AI 业务融合实践
大数据·agent·mcp
雮尘4 天前
让 AI Agent 高效并行开发的命令-git worktree
人工智能·git·agent