Could I change my name and surname in all previous commits?

后端 未结 6 1201
春和景丽
春和景丽 2020-11-27 08:57

I would like to change my name, surname and email in my all commits, is it possible?

6条回答
  •  轮回少年
    2020-11-27 09:48

    Save the script below as e.g. ~/.bin/git-replace-author and run it using, e.g:

    git replace-author "John Ssmith" "John Smith" "johnsmith@example.com"
    

    With no arguments, it updates all commits with your name to use your current email address according to Git config.

    DEFAULT_NAME="$(git config user.name)"
    DEFAULT_EMAIL="$(git config user.email)"
    export OLD_NAME="${1:-$DEFAULT_NAME}"
    export NEW_NAME="${2:-$DEFAULT_NAME}"
    export NEW_EMAIL="${3:-$DEFAULT_EMAIL}"
    
    echo "Old:" $OLD_NAME "<*>"
    echo "New:" "$NEW_NAME <$NEW_EMAIL>"
    echo "To undo, use: git reset $(git rev-parse HEAD)"
    
    git filter-branch --env-filter \
    'if [ "$GIT_AUTHOR_NAME" = "${OLD_NAME}" ]; then
        export GIT_AUTHOR_NAME="${NEW_NAME}"
        export GIT_AUTHOR_EMAIL="${NEW_EMAIL}"
        export GIT_COMMITTER_NAME="${NEW_NAME}"
        export GIT_COMMITTER_EMAIL="${NEW_EMAIL}"
    fi'
    

    Raw (to download)

提交回复
热议问题