批量修改 git 仓库 commit 的邮箱和用户名

144 阅读1分钟

遇到了这样的需求:把所有邮箱为 A 的 commit 修改为 B 邮箱。

首先安装一个 Python 包:

pip install git-filter-repo

然后在对应 git 仓库执行指令:

git filter-repo --commit-callback '
if commit.author_email == b"旧邮箱@example.com":
    commit.author_name = b"正确的名字"
    commit.author_email = b"新邮箱@example.com"
if commit.committer_email == b"旧邮箱@example.com":
    commit.committer_name = b"正确的名字"
    commit.committer_email = b"新邮箱@example.com"
'

有必要的话再执行一下 git push --force,就大功告成了。