1. 程式人生 > >修改 github 已提交使用者名稱和郵箱

修改 github 已提交使用者名稱和郵箱

開啟終端 新建臨時倉庫

git clone --bare https://github.com/user/repo.git
cd repo.git

寫入執行指令碼

vim git-author-rewrite.sh
#!/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

執行指令碼

chmod 777 git-author-rewrite.sh
./git-author-rewrite.sh
git push --force --tags origin 'refs/heads/*'

刪除臨時倉庫