Zero's Blog - Git https://l2dy.sourceforge.io/tag/Git/ zh-CN Wed, 05 May 2021 11:04:00 +0000 Wed, 05 May 2021 11:04:00 +0000 清理已经提交到 Git 仓库但后续纳入 gitignore 的文件 https://l2dy.sourceforge.io/2021/05/05/gitignore-clean.html https://l2dy.sourceforge.io/2021/05/05/gitignore-clean.html Wed, 05 May 2021 11:04:00 +0000 Zero git ls-files -ziX .gitignore | xargs -0 git rm

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

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

git rm -r --cached .
git add .
]]>
0 https://l2dy.sourceforge.io/2021/05/05/gitignore-clean.html#comments https://l2dy.sourceforge.io/feed/tag/Git/