10
如何批量修改 Git 提交记录中的作者名称和邮箱
source link: https://ttys3.dev/post/git-batch-change-commit-author-and-email/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
如何批量修改 Git 提交记录中的作者名称和邮箱
2020-09-07
:: 荒野無燈
:: Mod 2020-09-07(5321be6)
#Git
September 7, 2020
适用场景:
已经提交了N个commit才发现用的配置(
user.name
和user.email
)错了,比如要用个人邮箱的,用成了公司邮箱。 基于隐私考虑,我们需要把公司邮箱和昵称替换掉。
主要是用到 git-filter-repo的CALLBACKS功能
方法很简单:
#将所有用户名中包含的foo替换成ttys3 (注意,不支持中文)
git filter-repo --name-callback 'return name.replace(b"foo", b"ttys3")'
#将所有commit信息的email中包含的 [email protected] 替换成 [email protected]
git filter-repo --email-callback 'return email.replace(b"[email protected]", b"[email protected]")'
- 替换是部分匹配的,因此注意使用尽可能长的子串
- 操作会重写所有被匹配到的commit, 因此,如果repo已经push到了远程仓库时,操作要慎重
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK