Skip to content
vast-cow's blog
Go back

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

Edit page

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"\nnew_email=b"new@example.com"\nif (commit.author_name==new_name and commit.author_email==new_email and commit.committer_name==new_name and commit.committer_email==new_email):\n    return\ncommit.author_name=new_name\ncommit.author_email=new_email\ncommit.committer_name=new_name\ncommit.committer_email=new_email'

Install

pip install git-filter-repo

How it works:

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.


Edit page
Share this post:

Comments


Previous Post
Bridging a System-Level systemd Target to the User Instance
Next Post
Set up a bcache partition and evaluate its performance