git 修改 .gitignore 不生效

    在使用 Git 时候,发现在 .gitignore 文件中添加内容后,推送成功后并没有生效。

出错原因:

.gitignore 文件的内容不对历史文件生效

情景复现:

1. 远端已经有了 .idea 配置文件夹
2. 在 .gitignore 中添加 .idea
3. commit && push 这个 .gitignore 文件的更改
4. 发现远端仓库中仍有 .idea 的文件夹,并未被忽略掉

解决方法:

// 清除本地缓存
git rm -r --cached .

// 重新 trace file
git add.

// 重新提交
git commit -m "update .gitignore"

// 推送远端
git push origin master

 

参考资料:

https://blog.csdn.net/mingjie1212/article/details/51689606

posted on 2021-06-07 00:46  爱笑的张飞  阅读(255)  评论(0编辑  收藏  举报

导航