Laziness, Impatience and Hubris.

修改Git已提交的Email和Name

预计 2 分钟

由于在Windows上使用Git的千奇百怪解决方案造成中途需要从babun更换到cygwin..结果更换的时候将Git配置中的Email输入错误,于是寻找了一下修改多个commit中的信息. 最后在changing-author-info中看到了解决方案. 保存脚本

#!/bin/sh

git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
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

然后运行即可.