Skip to content

Instantly share code, notes, and snippets.

@mikaello
Last active March 5, 2025 21:35
Show Gist options
  • Save mikaello/37d52d73d064d7f770b457ba67f6c796 to your computer and use it in GitHub Desktop.
Save mikaello/37d52d73d064d7f770b457ba67f6c796 to your computer and use it in GitHub Desktop.
Change Git commit author / email in existing commits

Docs: https://github.com/newren/git-filter-repo/blob/main/Documentation/converting-from-filter-branch.md#changing-authorcommittertagger-information and https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html#_filtering_of_names_amp_emails_see_also_name_callback_and_email_callback

git filter-repo \
  --email-callback ' return email if email != b"OLD_EMAIL" else b"NEW_EMAIL" ' \
  --name-callback 'return name.replace(b"OLD_AUTHOR", b"NEW_AUTHOR")' \
  --force \
  --refs HEAD~<NUMBER_OF_COMMITS>..<BRANCH_NAME> # This line is optional, remove to do the change in all commits (will rewrite complete history)
@matschundbrei
Copy link

Note:

In some of our cases we need to filter for author names containing non-ascii characters. In that case, instead of a bytes-array (b"OLD_AUTHOR"), you might want to use explicit encoding like "Öld Äüthör".encode("utf-8")

See also Python Docs: str.encode

Cheers,
M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment