修改历史提交者的邮箱
1. 查看提交者⚓
显示提交的 author
和 commiter
:
git log --pretty=full
2. 修改最新提交⚓
首先,配置正确的 user.name
和 user.email
(否则将只修改 Author),将 author
和 commiter
一并修改:
git commit --amend --no-edit --author="Author Name<email@address.com>"
3. 批量修改⚓
Note
注意,这样会重写多个提交信息
#!/bin/sh
# 修改历史提交者的邮箱
git filter-branch --env-filter '
OLD_EMAIL="old@email.com"
CORRECT_EMAIL="correct@email.com"
CORRECT_NAME="correct_name"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' HEAD
只修改邮箱版本:
git filter-branch -f --env-filter '
old_email="old@email.com"
new_email="new@email.com"
if [ "$GIT_COMMITTER_EMAIL" = "$old_email" ]
then
export GIT_COMMITTER_EMAIL="$new_email"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$old_email" ]
then
export GIT_AUTHOR_EMAIL="$new_email"
fi
' HEAD