Skip to content

Instantly share code, notes, and snippets.

@HorridModz
Created August 12, 2025 01:17
Show Gist options
  • Save HorridModz/3c9594a9c1db4a85f249b226a99df722 to your computer and use it in GitHub Desktop.
Save HorridModz/3c9594a9c1db4a85f249b226a99df722 to your computer and use it in GitHub Desktop.
Fix Github Commits Author
@echo off
REM This batch script will change the email address of certain commits within a git repository.
REM This is useful if you committed under the wrong email address or used the wrong account.
REM Usage:
REM 1. Make sure you have python3 installed, and install git-filter-repo (https://github.com/newren/git-filter-repo) using pip install git-filter-repo
REM 2. Download the python script git_fix_commits.py and fill in the variables OLD_NAMES and OLD_EMAILS (list of any names / emails you would like to replace),
REM as well as CORRECT_NAME and CORRECT_EMAIL (the correct name and email address you would like to use in the rewritten commit).
REM 3. Change the PYTHON_SCRIPT variable in the line below
REM 4. Open a terminal in the git repository you would like to apply your changes in
REM 5. If necessary, stash any uncommitted changes with git stash (after completing this process, you can use git stash pop to restore them)
REM 6. If necessary, sync the remote repository's commits using git pull
REM 7. Run this script to rewrite the local commit history
REM 8. Overwrite the remote repository's commit history with git push --force (Note that this command can be dangerous! Be careful before force pushing!)
REM Put the path to your corresponding python script here (use DOUBLE BACKSLASHES)
set "PYTHON_SCRIPT=C:\\Users\\zachy\\!Scripts\\git_fix_commits.py"
REM Delete previous log
if exist filter_log.txt del filter_log.txt
REM Run git-filter-repo with the Python callback
git filter-repo --force --commit-callback "exec(open(\"%PYTHON_SCRIPT%\").read())"
REM Print the log if it exists
if exist filter_log.txt (
echo.
type filter_log.txt
) else (
echo.
echo No commits were edited.
)
"""
Don't run this directly.
Instead, run the git_fix_commits.bat script.
"""
OLD_NAMES = {"REDACTED"}
OLD_EMAILS = {"REDACTED"}
CORRECT_NAME = "REDACTED"
CORRECT_EMAIL = "REDACTED"
LOGFILE = "filter_log.txt"
changed = False
if (commit.author_name in [name.encode() for name in OLD_NAMES]) or (commit.author_email in [email.encode() for email in OLD_EMAILS]):
commit.author_name = CORRECT_NAME.encode()
commit.author_email = CORRECT_EMAIL.encode()
changed = True
if (commit.committer_name in [name.encode() for name in OLD_NAMES]) or (commit.committer_email in [email.encode() for email in OLD_EMAILS]):
commit.committer_name = CORRECT_NAME.encode()
commit.committer_email = CORRECT_EMAIL.encode()
changed = True
if changed:
with open(LOGFILE, "a+") as f:
print(f"Changed author of commit {commit.original_id.decode('ascii')} to {CORRECT_NAME}, {CORRECT_EMAIL}", file=f, flush=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment