开发需要,本地维护了多个用户名和邮箱组合,今天提交代码后,发现用户名和邮箱错了,由于是贡献的开源代码,必须改回来。
git config user.name "example"
git config user.email "example@163.com"
git config --global user.name "example"
git config --global user.email "example@163.com"
git commit --amend --author="userName <userEmail>"
git filter-branch –env-filter ‘
if [ “GIT_AUTHOR_NAME” = “oldName” ]
then
export GIT_AUTHOR_NAME=”newName”
export GIT_AUTHOR_EMAIL=”newEmail”
fi ‘ HEAD~3..HEAD
git filter-branch –env-filter ‘
if [ “GIT_COMMITTER_NAME” = “oldName” ]
then
export GIT_COMMITTER_NAME=”newName”
export GIT_COMMITTER_EMAIL=”newEmail”
fi ‘ HEAD~3..HEAD
如果提示:
Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f
可以加上-f,即git filter-branch -f –env-filter。