To rewrite author information such as author usernames and emails for previous commits, first add an alias for the change-commits command.
1
git config --global 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"
To change author name and email address,
1
2
git change-commits GIT_AUTHOR_NAME "old name" "new name"
git change-commits GIT_AUTHOR_EMAIL "old@email.com" "new@email.com"
To specify the number of previous commits to rewrite,
1
2
# e.g. edit past 3 commits
git change-commits GIT_AUTHOR_NAME "old name" "new name" HEAD~3..HEAD
However when you attempt to edit both of them(i.e. more than once), it crashes with the existing backup.
1
2
3
Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f
Remove the original backup.
1
git update-ref -d refs/original/refs/heads/<branch-name>
This changes the author without changing the commit date.
However, it does NOT reconfigure the commit author.