Skip to content

Instantly share code, notes, and snippets.

@poqdavid
Last active January 9, 2024 17:49
Show Gist options
  • Save poqdavid/2509214dd9132f6ec77685673baea4de to your computer and use it in GitHub Desktop.
Save poqdavid/2509214dd9132f6ec77685673baea4de to your computer and use it in GitHub Desktop.
How to rename author and resign all commits

1. Rename author

Note that filter-repo deletes remote section in .git\config

git filter-repo --mailmap mymailmap --force

or

git-filter-repo --name-callback 'return name.replace(b"<OLD NAME>", b"<NEW NAME>")'

2. Sign all commits

git filter-branch -f --commit-filter 'git commit-tree -S "$@";' -- --all

or

This option is for signing all commits for specific author name

git filter-branch -f --commit-filter '
if [ "$GIT_AUTHOR_NAME" = "<AUTHOR>" ];
then
    git commit-tree -S "$@";
fi' -- --all

3. Delete all backups/dupes made by filter-branch

git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now

4. Force push to origin

git push --force --tags origin 'refs/heads/*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment