其他分享
首页 > 其他分享> > .gitignore文件不生效

.gitignore文件不生效

作者:互联网

1、需求:之前上传一个项目,把node_modules的依赖也上传了,文件多又大,让人头皮发麻,就想着去掉依赖,毕竟有package.json就够了

2、解决:就想着加个.gitignore文件来忽略node_modules文件,没想到加了之后不生效,查了一下,大致原因就是说如果某些文件已经被纳入了版本管理中,就算是在.gitignore中已经声明了忽略路径也是不起作用的

.gitignore

node_modules/

3、比较粗暴的方法:删(干)除(掉).git文件,重新初始化git init并加上.gitignore文件重新提交所有代码

4、要保留提交记录的话:就要删除缓存,再提交

git rm -r --cached .
git add .
git commit -m "chore: update .gitignore"
git push

 

标签:node,文件,git,modules,提交,生效,gitignore
来源: https://www.cnblogs.com/lovewhatIlove/p/16123694.html