git clone --bare https://github.com/user/repo.git
cd repo.git
OLD_EMAIL:原来的邮箱
CORRECT_NAME:更正的名字
CORRECT_EMAIL:更正的邮箱
将下面代码复制放到命令行中执行
git filter-branch -f --env-filter '
OLD_EMAIL="原来的邮箱"
CORRECT_NAME="更正的名字"
CORRECT_EMAIL="更正的邮箱"
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
' --tag-name-filter cat -- --branches --tags
执行后等待一会
git push --force --tags origin 'refs/heads/*'
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
若遇到以上错误。
git pull
确保最新代码
git pull --allow-unrelated-histories
# 或者指定分枝
git pull origin master --allow-unrelated-histories
fatal: This operation must be run in a work tree 若提示这行报错。
请在在工作目录运行。
原文: http://yiqiao.me/articles/12/git-batch-modification-submission-username-email
版权声明: 自由转载-非商用-非衍生-保持署名 (创意共享3.0许可证)