git filter-repo(官方推荐)比
git filter-branch和 BFG 更安全、现代
⚠️ 下面操作会改写历史
⚠️ 一旦推送,所有旧 commit hash 都会变
⚠️ 私有仓库 → 公共仓库,这是正确时机
👉 先备份仓库一份!
git clone --mirror 你的私有仓库.git
cd 你的私有仓库.git
--mirror 会包含:
git-filter-repopip install git-filter-repo
(Git ≥ 2.22 有时已内置)
123.45.67.89)replacements.txtreplacements.txt 中写入你要替换的文本内容,如:123.45.67.89==your.domain.com
git filter-repo --replace-text replacements.txt
或者直接删除(修改 replacements.txt ):
123.45.67.89
你可以在 replacements.txt 中使用正则:
regex:\b\d{1,3}(\.\d{1,3}){3}\b==REDACTED_IP
👉 所有效果:
REDACTED_IPgit grep -nE '\b\d{1,3}(\.\d{1,3}){3}\b'
如果没有任何输出,说明历史里已经没 IP 了。
git remote remove origin
git remote add origin https://github.com/你的用户名/花再具箱.git
git push --force --all
git push --force --tags
⚠️ --force 是必须的(历史被改写)