It’s pretty common that I’ll accidentally use the wrong email for a commit. I have a few emails that I like to use for different purposes, so getting it correct is important :)
This one is nice and easy!
git commit --amend --author="Example Name <name@example.com>"
Using interactive rebase
git rebase -ion whatever base you want- Mark the commits you’d like to change with
edit, instead ofpick git commit --amend --author="Example Name <name@example.com>", thengit rebase --continue
Using filter branch
Filter the whole thing! Be careful though, filter-branch can break things if you’re not careful
git filter-branch -f --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "old@email.com" ];
then
GIT_AUTHOR_NAME="New Name";
GIT_AUTHOR_EMAIL="ne...
It’s pretty common that I’ll accidentally use the wrong email for a commit. I have a few emails that I like to use for different purposes, so getting it correct is important :)
This one is nice and easy!
git commit --amend --author="Example Name <name@example.com>"
Using interactive rebase
git rebase -ion whatever base you want- Mark the commits you’d like to change with
edit, instead ofpick git commit --amend --author="Example Name <name@example.com>", thengit rebase --continue
Using filter branch
Filter the whole thing! Be careful though, filter-branch can break things if you’re not careful
git filter-branch -f --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "old@email.com" ];
then
GIT_AUTHOR_NAME="New Name";
GIT_AUTHOR_EMAIL="new@email.com";
git commit-tree "$@";
else
git commit-tree "$@";
fi' HEAD
Using filter repo
I first mentioned git-filter-repo in split git repo, but it’s useful here too. Preferable to filter-branch, but not included in the base git install.
Install with
curl "https://raw.githubusercontent.com/newren/git-filter-repo/main/git-filter-repo" -o ~/.local/bin/git-filter-path
Then do either of the following
With mailmap
If you setup your mailmap to map old → new, you can run
git filter-repo --use-mailmap
Without mailmap
Otherwise, the following works well
git filter-repo --email-callback '
return email if email != b"old@email.com" else b"new@email.com"
'