本地有多个git账户,有时候提交没注意导致出现多个作者。

1.批量修改sh

这是我基于github官方文档修改的sh

#第一步---------------------------
#!/bin/sh

git filter-branch -f --env-filter '

OLD_EMAILs=("xx1@hotmail.com" "xx2@xx.com")
OLD_Names=("name1" "name2" "name3")

CORRECT_NAME="正确的名字"
CORRECT_EMAIL="正确的邮箱"

for old_Email in ${OLD_EMAILs[*]}; do
    if [ "$GIT_COMMITTER_EMAIL" = "$old_Email" ]; then
        echo 替换COMMITTER Email "$GIT_AUTHOR_NAME" 为 "$CORRECT_NAME" "$CORRECT_EMAIL"
        export GIT_COMMITTER_NAME="$CORRECT_NAME"
        export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
    fi
    if [ "$GIT_AUTHOR_EMAIL" = "$old_Email" ]; then
        echo 替换AUTHOR Email "$GIT_AUTHOR_NAME" 为 "$CORRECT_NAME" "$CORRECT_EMAIL"
        export GIT_AUTHOR_NAME="$CORRECT_NAME"
        export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
    fi
done

for name in ${OLD_Names[*]}; do
    if [ "$GIT_AUTHOR_NAME" = ${name} ]; then
        echo 替换Name "$GIT_AUTHOR_NAME" 为 "$CORRECT_NAME" "$CORRECT_EMAIL"
        export GIT_AUTHOR_NAME="$CORRECT_NAME"
        export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
    fi
done

' --tag-name-filter cat -- --branches --tags

#第二步-------------------------------
git push --force --tags origin 'refs/heads/*'

2.使用方法:

  • 全部修改上面的sh
OLD_EMAILs=("xx1@hotmail.com" "xx2@xx.com")
OLD_Names=("name1" "name2" "name3")

CORRECT_NAME="正确的名字"
CORRECT_EMAIL="正确的邮箱"
  • 在需要修改的工程,打开命令行bash或者powershell等。
  • 粘贴所有代码
  • 执行,完事