Skip to content

Instantly share code, notes, and snippets.

@0xdeepmehta
Created November 1, 2023 10:02
Show Gist options
  • Save 0xdeepmehta/b3b9e5d7dabfd3b55af8ccb55adf5e70 to your computer and use it in GitHub Desktop.
Save 0xdeepmehta/b3b9e5d7dabfd3b55af8ccb55adf5e70 to your computer and use it in GitHub Desktop.
#!/bin/sh
git filter-branch --env-filter '
if [ "$GIT_COMMITTER_EMAIL" = "old_email" ]; then
export GIT_COMMITTER_EMAIL="new_email"
fi
if [ "$GIT_AUTHOR_EMAIL" = "old_email" ]; then
export GIT_AUTHOR_EMAIL="new_email"
fi
' --tag-name-filter cat -- --branches --tags
@0xdeepmehta
Copy link
Author

0xdeepmehta commented Nov 1, 2023

The git filter-repo command is a more efficient and flexible way to rewrite history and replace old email addresses in your Git history. Based on the script you provided, here's how you can use git filter-repo to achieve the same result.

First, you need to create a mailmap file. This file will map the old email addresses to the new ones. Let's call this file mailmap.txt:

[email protected] [email protected]
In this file, the format is . The new email address is the one you want to replace the old one with.

Then, you can run the git filter-repo command with the --mailmap option, passing in your mailmap.txt file:

git filter-repo --mailmap mailmap.txt
This command will rewrite the entire history of your Git repository, replacing the old email address with the new one in all commits and tags where the old email was used as the author or committer email.

In the end, you will have a new Git history with the updated email addresses.

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