[Git] .gitignore 文件不生效解决方法

Published on
21
  • 把某些目录或文件加入忽略规则,按照上述方法定义后发现并未生效,原因是 .gitignore 只能忽略那些原来没有被追踪的文件,如果某些文件已经被纳入了版本管理中,则修改 .gitignore 是无效的。

  • 解决方法就是先把本地缓存删除(改变成未被追踪状态),然后再提交:

$ git rm -r --cached .
$ git add .
$ git commit -m 'update .gitignore'
$ git push


Prev Post 解决Windows11远程桌面提示Windows Defender Credential Guard 不允许使用已保存的凭据的问题
Next Post [Rust] 多线程并发访问