利用脚本

代码根目录下创建:
vi changelog.sh, 粘贴如下代码并保存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh

git filter-branch --env-filter '

OLD_EMAIL="lihongli@gmail.com"
CORRECT_NAME="iodefog"
CORRECT_EMAIL="iodefog@gmail.com"

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

把 OLD_EMAIL 、CORRECT_NAME 、 CORRECT_EMAIL 改成自己的新旧邮箱用户名即可;

执行代码:

sh changelog.sh

如果遇到如下错误 :

1
Cannot create a new backup. A previous backup already exists in refs/original/ Force overwriting the backup with -f

则执行如下命令;

1
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch Rakefile' HEAD

最后覆盖远端仓库:

1
2
3
git push origin --force --all

git push origin --force --tags