如何清理 git 历史
- 下载 下载BFG Repo-Cleaner工具,如 bfg-1.14.0.jar。
- 把敏感信息在当前最新版本里都删除。
- 使用mirror标志克隆一个裸仓库(普通文件将处于不可见):
git clone --mirror git@git.woa.com:aaa/myproject myproject_rmhistory
。 - 生成一个 rule 文件,如 rule.txt:
testpass
。每一行一个敏感词。 java -jar bfg-1.14.0.jar --replace-text rule.txt myproject_rmhistory
。cd myproject_rmhistory
。git reflog expire --expire=now --all && git gc --prune=now --aggressive
。- 关闭对 master 的写保护:
git push -f
。
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.