DEV Community

vast cow
vast cow

Posted on

Changing Author Information in Git History with `git filter-repo`

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'
Enter fullscreen mode Exit fullscreen mode

Install

pip install git-filter-repo
Enter fullscreen mode Exit fullscreen mode

How it works:

  • commit.author_name and commit.author_email: update the original author of each commit.
  • commit.committer_name and commit.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:

  1. Backup first: Rewriting history changes commit IDs. It’s a good idea to back up your repository before running this command.
  2. Force push required: After rewriting history, you will need to push your changes with git push --force if the repository is shared.
  3. 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)