Git - GPG 签名在提交名称和电子邮件更改后失败

Git - GPG signing fails after commit name & email change

我有一个本地 git 存储库,其中包含大量使用我的真实姓名和个人电子邮件进行的提交。我想将这些推送到 GitHub,但不使用我的个人详细信息。

我使用以下命令重写了每次提交的名称和电子邮件:

git filter-branch -f --env-filter \
"GIT_AUTHOR_NAME='github_username'; GIT_AUTHOR_EMAIL='github_username@users.noreply.github.com'; \
GIT_COMMITTER_NAME='github_username'; GIT_COMMITTER_EMAIL='github_username@users.noreply.github.com';" HEAD

在此之后执行 git log 时一切看起来都很好。我的私人邮箱不见了。

然后我尝试使用以下方式对每个提交进行 GPG 签名:

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

但是在第一次提交时我收到以下错误:

Rewrite 1124486cba6a6f6432adb24f7c66833d860b191f (1/38) (1 seconds passed, remaining 37 predicted)    
gpg: skipped "My Real Name <my_real_email@gmail.com>": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
could not write rewritten commit

它从哪里得到我的旧用户名和密码?

原来最后的 -- --all 是罪魁祸首。将其更改为 HEAD 效果很好。

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