重写 Git 历史的现代工具
git-filter-repo 用于删除敏感文件、重写作者信息、拆分仓库和清理大文件。它会改写提交哈希,属于破坏性操作,必须在协调后对镜像执行。
git filter-repo --analyze
git filter-repo --path secret.env --invert-paths
git filter-repo --path docs/ --invert-paths
git filter-repo --replace-text replacements.txt
git filter-repo --mailmap .mailmap
git filter-repo --strip-blobs-bigger-than 10M
git filter-repo --force
replacements.txt:
old-password==>REDACTED
old-email@example.com==>new-email@example.com
--path 和 --invert-paths 组合语义要确认,避免删错目录。.mailmap 只改显示映射;要真正改作者信息用 --mailmap 的 filter-repo 语义。gc,并确认 LFS 指针没有被误删。git — 版本控制git-reflog — 恢复误操作git-bundle — 操作前备份