修改GitHub记录中的invalidemailaddress

原文:https://github.com/kadishmal/tilchi.com/wiki/GitHub-Fix-invalid-email-address-in-Repository-History

向github提交commit的时候,如果邮件地址设置不符合格式,提交的作者信息就会变成invalid-email-address,修改的方法如下

新建一个fix_repo.sh文件:

cd my_repo
touch fix_repo.sh
fix_repo.sh文件中加入下面内容,将xxx@xxx替换为yyy@yyy.yy
别漏掉最后一行的引号
#!/bin/sh

git filter-branch --env-filter '

am="$GIT_AUTHOR_EMAIL"
cm="$GIT_COMMITTER_EMAIL"

if [ "$GIT_COMMITTER_EMAIL" = "xxx@xxx" ]
then
    cm="yyy@yyy.yy"
fi
if [ "$GIT_AUTHOR_EMAIL" = "xxx@xxx" ]
then
    am="yyy@yyy.yy"
fi

export GIT_AUTHOR_EMAIL="$am"
export GIT_COMMITTER_EMAIL="$cm"
'

添加可执行属性

chmod a+x fix_repo.sh

然后执行

./fix_repo.sh

之后push就可以了,因为修改了以前的commit信息,push会error,这时要push -f

git push -f

多次执行./fix_repo.sh时,如果遇到
Cannot create new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f

git update-ref -d refs/original/refs/heads/master
原文地址:https://www.cnblogs.com/gamesun/p/3036797.html