How to change the author and committer name and e-mail of multiple commits in Git?

后端 未结 30 3151
野性不改
野性不改 2020-11-21 04:50

I was writing a simple script in the school computer, and committing the changes to Git (in a repo that was in my pendrive, cloned from my computer at home). After several c

30条回答
  •  你的背包
    2020-11-21 05:11

    You can use this as a alias so you can do:

    git change-commits GIT_AUTHOR_NAME "old name" "new name"
    

    or for the last 10 commits:

    git change-commits GIT_AUTHOR_EMAIL "old@email.com" "new@email.com" HEAD~10..HEAD
    

    Add to ~/.gitconfig:

    [alias]
        change-commits = "!f() { VAR=$1; OLD=$2; NEW=$3; shift 3; git filter-branch --env-filter \"if [[ \\\"$`echo $VAR`\\\" = '$OLD' ]]; then export $VAR='$NEW'; fi\" $@; }; f "
    

    Source: https://github.com/brauliobo/gitconfig/blob/master/configs/.gitconfig

    Hope it is useful.

提交回复
热议问题