Fixing Commit Author Information
You committed using the wrong name or email — maybe you used your personal email on a work machine, or a CI bot committed under the root user. This page covers every scenario: fixing the last commit, fixing multiple commits with interactive rebase, and fixing all commits with a wrong email across the entire repository history.
First: configure Git correctly to prevent future mistakes
Set global author information
git config --global user.name "Jane Developer" git config --global user.email "jane@company.com" # Verify git config --global user.name git config --global user.email # For a specific repo only (overrides global) git config user.email "jane@personal.com"
Check the current author configuration
git config --list --show-origin | grep user # file:/Users/jane/.gitconfig user.name=Jane Developer # file:/Users/jane/.gitconfig user.email=jane@company.com
Fix the last commit only
Amend author on most recent commit
# Fix both name and email in one command git commit --amend --author="Jane Developer <jane@company.com>" --no-edit # [main abc1234] Your commit message # Author: Jane Developer <jane@company.com> # Date: Mon Jan 13 15:00:00 2025 +0000
Reset author to current git config
# If git config is already correct, just reset author to config values git commit --amend --reset-author --no-edit
Fix multiple commits with interactive rebase
If the wrong author is on several recent commits, use interactive rebase to step through each one and amend it.
Rebase interactively over the last 4 commits
git rebase -i HEAD~4 # Opens your editor with a list: # pick abc1234 Add login feature # pick def5678 Fix validation bug # pick ghi9012 Update styles ← wrong author # pick jkl3456 Add tests ← wrong author
Change 'pick' to 'edit' for commits to fix
pick abc1234 Add login feature pick def5678 Fix validation bug edit ghi9012 Update styles edit jkl3456 Add tests
Fix each commit when rebase pauses
# Rebase pauses at ghi9012 git commit --amend --author="Jane Developer <jane@company.com>" --no-edit git rebase --continue # Rebase pauses at jkl3456 git commit --amend --author="Jane Developer <jane@company.com>" --no-edit git rebase --continue # All done # Successfully rebased and updated refs/heads/main.
Fix all commits with a specific wrong email (entire history)
If you need to update the author across the entire repository history — for example, you used a personal email for months — use git filter-repo.
Fix all commits with wrong email using filter-repo
# Install filter-repo if needed: pip install git-filter-repo # Create a mailmap file cat > mailmap.txt << 'EOF' Jane Developer <jane@company.com> <jane@personal.com> Jane Developer <jane@company.com> <root@ci-server> EOF # Apply the mailmap to rewrite all commit author and committer fields git filter-repo --mailmap mailmap.txt
Alternative: use a Python callback for complex remapping
git filter-repo --email-callback ' return email.replace(b"old@wrong.com", b"jane@company.com") '
Fix using git filter-repo --commit-callback (full control)
Rewrite both author name and email
git filter-repo --commit-callback '
if commit.author_email == b"root@localhost":
commit.author_name = b"Jane Developer"
commit.author_email = b"jane@company.com"
commit.committer_name = b"Jane Developer"
commit.committer_email = b"jane@company.com"
'After rewriting history: force-push
Push the rewritten history
# filter-repo removes the origin remote as a safety measure git remote add origin https://github.com/user/repo.git # Force-push all branches git push origin --all --force-with-lease git push origin --tags --force-with-lease
Comparison: which method to use
Scope | Method | History impact |
|---|---|---|
Last commit only, not pushed | git commit --amend --author | Single commit hash changes |
Last commit, already pushed | git commit --amend + force-push | Single commit; warn teammates |
Last N commits | git rebase -i HEAD~N + amend | N commits rewritten |
All commits with wrong email | git filter-repo --mailmap | All commit hashes change |
Complex remapping logic | git filter-repo --commit-callback | All commit hashes change |
Verifying the fix
Check author on recent commits
git log --format="%h %an <%ae> %s" -10 # abc1234 Jane Developer <jane@company.com> Add login feature # def5678 Jane Developer <jane@company.com> Fix validation bug # ghi9012 Jane Developer <jane@company.com> Update styles
Find all unique authors in the repository
git log --all --format="%an <%ae>" | sort -u # CI Bot <ci@build-server.internal> # Jane Developer <jane@company.com> # Root User <root@localhost> ← these should be fixed
Using .mailmap for display-only correction
If you only want to correct how author names appear (without rewriting history), Git supports a .mailmap file in the root of the repository. This does not change any commit hashes — it only affects display in git log and git shortlog.
.mailmap file format
# Canonical name <canonical email> <old email> Jane Developer <jane@company.com> <jane@personal.com> Jane Developer <jane@company.com> <root@localhost> # Canonical name <canonical email> Old Name <old email> Jane Developer <jane@company.com> Jane D <jane@old-employer.com>
Verify .mailmap is working
git shortlog -sne # 47 Jane Developer <jane@company.com> # 3 CI Bot <ci@build-server.internal>
Prevention: per-directory author overrides
Use
git config user.email(no--global) inside work repos to override the global email.Add an
includeIfblock in~/.gitconfigto auto-switch configs based on directory path.
~/.gitconfig with conditional include
[user] name = Jane Developer email = jane@personal.com [includeIf "gitdir:~/work/"] path = ~/.gitconfig-work
~/.gitconfig-work
[user] email = jane@company.com