git config user.name "现在的名字"
git config user.email "现在的邮箱"
1、有限次修改
a) 修改最后一次
git commit --amend --author="NewAuthor <NewEmail@address.com>"
b) 修改某次
# 获取倒数几次提交信息
git rebase -i HEAD~2
需要修改哪次提交,就修改pick
为edit
,保存退出。(涉及vim操作)
git commit --amend
git rebase --continue
git push --force origin master
2、脚本批量修改
git clone --bare https://github.com/XXX/XXX.git
项目中新建一个脚本modify.sh
#!/bin/sh
git filter-branch --env-filter '
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
if [ "$GIT_COMMITTER_EMAIL" = "原来的邮箱" ]
then
cn="现在的名字"
cm="现在的邮箱"
fi
if [ "$GIT_AUTHOR_EMAIL" = "原来的邮箱" ]
then
an="现在的名字"
am="现在的邮箱"
fi
export GIT_AUTHOR_NAME="$an"
export GIT_AUTHOR_EMAIL="$am"
export GIT_COMMITTER_NAME="$cn"
export GIT_COMMITTER_EMAIL="$cm"
'
git log检查提交记录是否修改正确,正确的话提交到远程
git push --force --tags origin 'refs/heads/*'
清理临时克隆XXX.git