How to Fix Wrong Git Commit Email Without Re‑committing

This guide explains how to correct an incorrect author email in Git commits—both for the most recent commit and for the entire history—using amend, filter‑branch scripts, and how to handle existing backup references.

Open Source Linux
Open Source Linux
Open Source Linux
How to Fix Wrong Git Commit Email Without Re‑committing

Modify the most recent commit's email

git commit --amend --author="NewAuthor <[email protected]>"

Batch modify email

Use the following script, replace the placeholders with your old and new information, then run it in the Git repository.

#!/bin/sh

git filter-branch --env-filter '
    an="$GIT_AUTHOR_NAME"
    am="$GIT_AUTHOR_EMAIL"
    cn="$GIT_COMMITTER_NAME"
    cm="$GIT_COMMITTER_EMAIL"

    if [ "$GIT_COMMITTER_EMAIL" = "[Your Old Email]" ]
    then
        cn="[Your New Author Name]"
        cm="[Your New Email]"
    fi
    if [ "$GIT_AUTHOR_EMAIL" = "[Your Old Email]" ]
    then
        an="[Your New Author Name]"
        am="[Your New Email]"
    fi

    export GIT_AUTHOR_NAME="$an"
    export GIT_AUTHOR_EMAIL="$am"
    export GIT_COMMITTER_NAME="$cn"
    export GIT_COMMITTER_EMAIL="$cm"
'

Q&A

A previous backup already exists in refs/original/

This message indicates a prior git filter-branch created a backup under refs/original/. Delete the backup with one of the following commands:

git update-ref -d refs/original/refs/heads/master
# or
git filter-branch -f --tree-filter 'rm -f test' -- --all

References

git modify commit author and email

git modify historical commit username and email

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GitscriptEmailcommitfilter-branchauthor
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.