Sushi 的自动更新提交使用的是个人邮箱地址,初衷是增加 contributions,但我逐渐意识到这是自讨苦吃:
血与泪凝结成的 24 commits 被无情地掩盖了光芒😢
此举还导致自动更新和手动修改的 commits 无法被有效区分。长痛不如短痛,我决定重写仓库的 Git 历史。
熟读 Pro Git book 的读者可能立马就会想到一个命令:git filter-branch
。我对这个“核武器选项”早有所耳闻,但从没实际用过,刚打开手册准备研究一番,一则警告扑面而来:
https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_the_nuclear_option_filter_branch
Consider using
git-filter-repo
, which is a Python script that does a better job for most applications.
都这样说了,那就瞧瞧这钦定工具好不好用。
git-filter-repo
是个单文件脚本(默默放下准备输入 pip install -r requirements.txt
的手),即下即用,Arch Linux 可以直接安装同名包。该工具提供了丰富的预置方法(参数)供调教 Git 历史,但显然它们都无法满足我的需求:
Update to version
看来必须当一回脚本小子了。git filter-branch
跑的是 Shell 脚本,而 git-filter-repo
跑的是 Python 脚本,我需要用到其 CALLBACKS 分类中的 --commit-callback
参数:
# "One important thing to note for all callbacks is that filter-repo uses bytestrings everywhere instead of strings"
if b"Update to version" in commit.message:
commit.author_name = b"github-actions[bot]"
commit.committer_name = b"github-actions[bot]"
commit.author_email = b"41898282+github-actions[bot]@users.noreply.github.com"
commit.committer_email = b"41898282+github-actions[bot]@users.noreply.github.com"
<aside> ⚠️ author 和 committer 绝大部分情况下需要一并修改,除非是 merge PR 或者打 patch 等情况。两者的区别:The author is the person who originally wrote the work, whereas the committer is the person who last applied the work.
</aside>
给苦力章鱼猫正名了!
脚本中的邮箱地址 41898282+github-actions[bot]@users.noreply.github.com
是 GitHub 为每位用户分配的隐私邮箱地址:
https://github.com/settings/emails
而邮箱地址中的 ID[1] 是通过查询 GitHub API 得到的。除此之外还可以使用另一个邮箱地址 action@github.com
,与之关联的是 @actions-user,但个人不推荐。