You’ve pushed your code to GitHub/GitLab, but didn’t set the correct author’s email - what now?
When you take a look at the remote code repository (GitHub, GitLab, or similar), the commit is linked to the wrong user.
Fix single git commit with the wrong email address/user name
Fix the git configuration in your terminal (local):
git config user.name "Your name" git config user.email "your@email.com"
Rebase
git rebase -i HEAD~1
An editor window pops up where the commit is marked as
pick
- change it toedit
and save.Git Amend
git commit --amend --reset-author
Finish the rebase
git rebase --continue
Push to the remote repository
git push -f origin master
Alternative
You can also work with git filter-branch
to fix the complete history.
This operation is unsafe, so proceed with care.
git filter-branch --env-filter 'export GIT_AUTHOR_EMAIL="correct@email.com";GIT_AUTHOR_NAME="correct name"'
git push -f origin master
Here’s a script that also corrects the committer:
#!/bin/sh
## Credits: https://stackoverflow.com/a/750191
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='Newname'
GIT_AUTHOR_EMAIL='new@email'
GIT_COMMITTER_NAME='Newname'
GIT_COMMITTER_EMAIL='new@email'
" HEAD
Then push to the remote repository: git push -f origin master
.