Zero's Blog - Git 2021-05-05T11:04:00+00:00 Typecho https://l2dy.sourceforge.io/feed/atom/tag/Git/ <![CDATA[清理已经提交到 Git 仓库但后续纳入 gitignore 的文件]]> https://l2dy.sourceforge.io/2021/05/05/gitignore-clean.html 2021-05-05T11:04:00+00:00 2021-05-05T11:04:00+00:00 Zero https://l2dy.sourceforge.io/ git ls-files -ziX .gitignore | xargs -0 git rm

缺点是如果仓库里有多个 .gitignore 文件,只能覆盖到当前目录的。

另一种比较危险的方案是移除所有文件再添加,注意先确保工作区干净。

git rm -r --cached .
git add .
]]>