New laptop, forgot to set user.email, and now the last commit has the wrong address on it. Changing the config doesn’t fix that commit, but one amend does.
git config user.email "[email protected]"
git commit --amend --no-edit --reset-author
--reset-author replaces the author name, email and author date with your current settings, so first fix the config, then amend. --no-edit keeps the message. Check the result with git log -1 --format='%an %ae'.
To set a specific author without changing your config, there’s --author:
git commit --amend --no-edit --author="Alice <[email protected]>"
For several commits in a row, I’d run it on each one during a rebase: git rebase -r main --exec 'git commit --amend --no-edit --reset-author'.
The same rule as every amend applies: this makes new commits with new hashes. That’s fine for work you haven’t pushed. Once it’s pushed to a shared branch, think twice, because rewriting means force pushing and other people having to deal with it. And it only fixes what’s in your repository. Commits already sent upstream with the old address stay there.
Further reading: git-commit documentation