Sometimes, you may need to update the author or committer information in your Git repository history. For example, if your email address has changed, or you want to fix a name typo in past commits. The git filter-repo tool makes this process easy and efficient.
Here is a command that rewrites all commits to use a new name and email:
git filter-repo --force --commit-callback 'new_name=b"New Name"; new_email=b"new@example.com"; if (commit.author_name==new_name and commit.author_email==new_email and commit.committer_name==new_name and commit.committer_email==new_email): return; commit.author_name=new_name; commit.author_email=new_email; commit.committer_name=new_name; commit.committer_email=new_email'
Install
pip install git-filter-repo
How it works:
-
commit.author_nameandcommit.author_email: update the original author of each commit. -
commit.committer_nameandcommit.committer_email: update the person who committed the change (often the same as the author).
This command ensures that every commit in your repository history shows the new name and email.
Important Notes:
- Backup first: Rewriting history changes commit IDs. It’s a good idea to back up your repository before running this command.
-
Force push required: After rewriting history, you will need to push your changes with
git push --forceif the repository is shared. - Coordinate with your team: Since commit hashes change, other contributors will need to re-clone or reset their local repositories.
By using git filter-repo, you can clean up your project’s commit history and make sure your author details are consistent.
Top comments (0)