Skip to content

Instantly share code, notes, and snippets.

@tristan
Created April 19, 2017 00:13
Show Gist options
  • Save tristan/9158556bb091099022a364376a1de23d to your computer and use it in GitHub Desktop.
Save tristan/9158556bb091099022a364376a1de23d to your computer and use it in GitHub Desktop.
Script to take the email address of a commit author and change every commit by that author to the new author
#!/bin/bash
set -euox pipefail
ORIG_AUTHOR=$1
NEW_AUTHOR=$2
for ORIG_HASH in $(git log --format=%h --author=$ORIG_AUTHOR); do
ORIG_BRANCH=$(git rev-parse --abbrev-ref HEAD)
CDATE=$(git show -s --format=%ci $ORIG_HASH)
git checkout $ORIG_HASH
GIT_AUTHOR_DATE=$CDATE GIT_COMMITTER_DATE=$CDATE git commit --amend --no-edit --author "$NEW_AUTHOR"
NEW_HASH=$(git rev-parse --short HEAD)
git replace $ORIG_HASH $NEW_HASH
git filter-branch -f -- --all
git replace -d $ORIG_HASH
git checkout $ORIG_BRANCH
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment