适用场景:
已经提交了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中包含的 foo@example.com 替换成 my-email@example.com
git filter-repo --email-callback 'return email.replace(b"foo@example.com", b"my-email@example.com")'
注意:
- 替换是部分匹配的,因此注意使用尽可能长的子串
- 操作会重写所有被匹配到的commit, 因此,如果repo已经push到了远程仓库时,操作要慎重