Skip to main content
🛡️ Verified Technical Content: Written by Serhii Hrekov. | Last reviewed & updated in Git: July 21, 2026

Git Commit Authors: How to Find, Change, and Configure Commit Identities

· 7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Every Git commit records two distinct identities: the Author (who originally wrote the code) and the Committer (who applied the changes to the branch). While these are usually the same person, they can diverge during operations like rebasing, cherry-picking, or merging.

Whether you need to trace who wrote a line of code or fix a typo in your own commit email, this guide covers how to find, change, and automatically configure Git commit author details.


How to Find Commit Authors and Emails

1. One-Liner Commands

If you need the name and email for the most recent commit or a specific commit hash:

  • For the latest commit:
    git log -1 --format="%an <%ae>"
  • For a specific commit hash:
    git show -s --format="%an <%ae>" <commit-hash>

2. Custom Formatting with git log

Standard git log output is verbose. You can customize the log layout using format placeholders:

  • %an: Author Name
  • %ae: Author Email
  • %cn: Committer Name
  • %ce: Committer Email

Show the last 5 commits with just the hash, author name, email, and subject:

git log -5 --pretty=format:"%h - %an <%ae> : %s"

To filter commits by a specific author:

git log --author="John Doe"

3. Line-by-Line Inspection with git blame

To see who modified specific lines in a file, run git blame. Use the -e flag to show email addresses instead of usernames:

git blame -e path/to/your/file.py

4. Raw Commit Object Inspection

To view the raw commit metadata stored on disk by Git, bypass standard formatting with cat-file:

git cat-file -p <commit-hash>

How to Change Commit Authors and Emails

Rewriting commit authors changes their parent-child cryptographic link. This means changing an author changes the commit hash, replacing old commits with brand-new ones.

1. Modify the Most Recent Commit

If you just committed changes and realized you used the wrong email:

  • Specify name and email manually:
    git commit --amend --author="New Name <newemail@example.com>" --no-edit
  • Reset to match your current git config:
    git commit --amend --reset-author --no-edit

2. Modify Specific Past Commits (Interactive Rebase)

If the bad commit is further back in history:

  1. Identify how many commits back the target commit is (e.g., 5 commits):
    git rebase -i HEAD~5
  2. In the editor that opens, change the word pick to edit (or e) next to the commit you want to modify. Save and close the editor.
  3. Once Git pauses at that commit, run:
    git commit --amend --author="Correct Name <email@example.com>" --no-edit
  4. Resume the rebase process:
    git rebase --continue

3. Mass Update the Entire Repository

If you need to replace an old or incorrect email across your entire commit history, use git-filter-repo (the modern, safe replacement for git filter-branch).

  1. Create a text file named my-mailmap mapping the old email to the new one:
    Correct Name <correct@email.com> <wrong@email.com>
  2. Run the filter command:
    git filter-repo --mailmap my-mailmap

Alternative: Legacy Shell Script (filter-branch)

If you cannot install external tools, use the built-in shell script filter. Note that this is slower and deprecated:

git filter-branch --env-filter '
OLD_EMAIL="wrong@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="correct@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

The Golden Rule: Pushing rewritten history

Because these operations rewrite commit hashes, you must force push to the remote server:

git push --force-with-lease

Warning: Never force push to a branch that other developers are actively collaborating on without coordinating with them first.


Preventing Mistakes: Conditional Configs

You can configure Git to automatically swap your author email based on the directory path of the repository (e.g., work repositories vs. personal projects).

In your global ~/.gitconfig file, set up conditional includes:

# Default settings
[user]
name = Serhii Hrekov
email = personal@example.com

# Apply work settings for projects inside ~/work/
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work

Then create a file named ~/.gitconfig-work with your work profile:

[user]
email = work@example.com

Sources