如何删除 git filter-branch 所做的备份

How to remove backups made by git filter-branch

我想在我的提交中修复姓名和电子邮件,所以我 运行

git filter-branch --env-filter '
if [ "$GIT_AUTHOR_NAME" = "<OLD NAME>" ];
then
    GIT_AUTHOR_NAME="<NEW NAME>";
    GIT_AUTHOR_EMAIL="<NEW EMAIL>";
fi
if [ "$GIT_COMMITTER_NAME" = "<OLD NAME>" ];
then
    GIT_COMMITTER_NAME="<NEW NAME>";
    GIT_COMMITTER_EMAIL="<NEW EMAIL>";
fi
' -- --all

git filter-branch -f --commit-filter 'git commit-tree -S "$@";' -- --all

但这会留下备份,我很难删除它们。

知道如何摆脱它们吗?

更好的选择,考虑到 git filter-branch or BFG are obsolete after Git 2.22 or more, is to use git filter-repo (python-based, to be installed first):

git filter-repo --path your/big/file --invert-path

或者:

git filter-repo --strip-blobs-bigger-than 10M

它的手册页提到,关于 git filter-branch:

Despite the use of --all and --tag-name-filter, and filter-branch's manpage claiming that a clone is enough to get rid of old objects, the extra steps to delete the other tags and do another gc are still required to clean out the old objects and avoid mixing new and old history before pushing somewhere.

git filter-repoforce you to make a backup first,然后继续更改您正在过滤的本地存储库的历史记录。


请注意,您仍然需要 git filter-repo 才能 签署 提交,如 newren/git-filter-repo discussions 209 中所述。

How do I cryptographically sign all commits on a branch?

或者,按照 OP POQDavid in 的建议:

git rebase --exec 'git commit --amend --no-edit -n -S' -i

或者,使用 rebase --root 选项 I mentioned here:

git rebase -i --root --exec 'git commit --amend --no-edit -n -S