网站首页 > 文章精选 正文
经常性更改个人邮箱,每次修改邮箱后,之前的提交的信息就与本人不同,会导致项目出现多个协作者,非常不爽。有以下几种解决方式。
方式一: 仅修改当前分支。GitHub 会显示为当前日期(Push Date),可以签名(GPG 签名)
方式二:会修改所有分支。GitHub 不会修改为当前日期,但是无法签名(GPG 签名),可配合 git filter-branch 工具签名。
方式一:使用原生的 Git 命令修改
- 只修改最近一次提交人信息
git commit --amend --author="New Name <new.email@example.com>" --no-edit
- 修改所有的历史记录
# 所有的历史记录
# 默认情况下,Git 会更新提交的日期。
git rebase -i --root
# 进入 VI 界面后,将所有记录 `commit` 前面的 `pick` 修改为 `edit`
# vi 快捷命令
:%s#pick#edit#g
# 保存
:wq
# 循环执行,直至最后报错
git commit --amend --author="New Name <new.email@example.com>" --no-edit
git rebase --continue
# 或者,使用 shell while 写个循环操作,直至其报错自动退出
while true; do git commit --amend --author="New Name <new.email@example.com>" --no-edit && git rebase --continue || break; done
- 强制更新
git push --force --all
方式二:使用第三方插件 git-filter-repo 修改
(注意,会清空 git repo url,需要先记录下来)
# 查看 repo url
git remote -v
- 根据条件指定条件
# 修改 author 信息
git filter-repo --commit-callback '
if commit.author_email == b"old.email@example.com":
commit.author_name = b"New Name"
commit.author_email = b"new.email@example.com"
' --force
# 修改 committer 信息
git filter-repo --commit-callback '
if commit.committer_email == b"old.email@example.com":
commit.committer_email = b"New Name"
commit.committer_email = b"new.email@example.com"
' --force
- *(可选)重新签名(打 GPG 签名)
git filter-branch -f --commit-filter '
git commit-tree -S "$@";
' --tag-name-filter cat -- --branches --tags
- 恢复 remote url
git remote add origin git@github.com:repo/example.git
- 强制更新
# 强制更新
git push --force --all
安装 git-filter-repo
pip install git-filter-repo
猜你喜欢
- 2025-06-12 看了这篇,我确定你已经彻底搞懂Git了
- 2025-06-12 今日头条架构师:头条1.2亿+日活的微服务和高可用架构实践
- 2025-06-12 隔离级别的追溯与究明,带你读懂隔离级别(下)
- 最近发表
- 标签列表
-
- newcoder (56)
- 字符串的长度是指 (45)
- drawcontours()参数说明 (60)
- unsignedshortint (59)
- postman并发请求 (47)
- python列表删除 (50)
- 左程云什么水平 (56)
- 编程题 (64)
- postgresql默认端口 (66)
- 数据库的概念模型独立于 (48)
- 产生系统死锁的原因可能是由于 (51)
- 数据库中只存放视图的 (62)
- 在vi中退出不保存的命令是 (53)
- 哪个命令可以将普通用户转换成超级用户 (49)
- noscript标签的作用 (48)
- 联合利华网申 (49)
- swagger和postman (46)
- 结构化程序设计主要强调 (53)
- 172.1 (57)
- apipostwebsocket (47)
- 唯品会后台 (61)
- 简历助手 (56)
- offshow (61)
- mysql数据库面试题 (57)
- fmt.println (52)