如果Git需要修改提交作者信息,名字邮箱名,可以用变基
1、找到需要修改信息的上一条sha值,执行:git rebase -i sha值
2、会出现一个文本
pick a4959eb ****
pick 5e10451 ****
# Rebase 1bd28ff..5e10451 onto 1bd28ff (2 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
把其中的pick修改成edit,保存文本并关闭
3、出现这样的提示
Stopped at d9252d1f... *******
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
4、输入git commit --amend --author "作者名字 <邮箱地址>" --no-edit
[detached HEAD 17f5733a] *****
Date: Sat May 6 17:45:49 2023 +0800
2 files changed, 122 insertions(+)
create mode 100644 *****
create mode 100644 *****
5、接着输入git rebase --continue
进入下一层提交
6、重复4、5,直到出现
Successfully rebased and updated refs/heads/*****
7、这时需要把变基后的提交强制推送到远端
git push --force origin 分支名