#!/bin/bash function unique_list_of_committers() { git log --format="%aN <%aE>" | sort -u } function change_author() { FROM_EMAIL=$1 FROM_NAME=$2 TO_EMAIL=$3 TO_NAME=$4 if [ -z "$FROM_EMAIL" ] || [ -z "$FROM_NAME" ] || [ -z "$TO_EMAIL" ] || [ -z "$TO_NAME" ]; then echo "usage: $0 " exit 1 fi if [ "$FROM_EMAIL" == "$TO_EMAIL" ] && [ "$FROM_NAME" == "$TO_NAME" ]; then echo "usage: $0 " echo "from and to emails and names are the same" exit 1 fi if [[ ! "$FROM_EMAIL" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then echo "usage: $0 " echo "from email is not valid" exit 1 fi if [[ ! "$TO_EMAIL" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then echo "usage: $0 " echo "to email is not valid" exit 1 fi git filter-branch -f --env-filter "GIT_COMMITTER_NAME='$FROM_NAME'; GIT_COMMITTER_EMAIL='$FROM_EMAIL'; GIT_AUTHOR_NAME='$TO_NAME'; GIT_AUTHOR_EMAIL='$TO_EMAIL';" HEAD; } printf 'listing unique committers before change:\n\n' unique_list_of_committers printf '\nchanging author..\n\n' change_author "$@" printf '\nlisting unique committers after change:\n\n'; unique_list_of_committers # example usage: # change-author.sh "from@mail.com" "to be changed" "to@mail.com" "change to"