Skip to content

Instantly share code, notes, and snippets.

@schnell18
Created December 12, 2013 02:56
Show Gist options
  • Save schnell18/7922568 to your computer and use it in GitHub Desktop.
Save schnell18/7922568 to your computer and use it in GitHub Desktop.
This script fixes the email in commit history. Usage: fix_git_eamil.sh <old_email> <new_email>
#!/bin/bash
# This script changes the emails of author and committer
# from the first argument to the second
old=$1
new=$2
if [[ -z $old ]]; then
echo "The original email is expected!"
exit 1
fi
if [[ -z $new ]]; then
echo "The new email is expected!"
exit 1
fi
if [[ ! $old =~ "@" ]]; then
echo "Invalid original email"
exit 1
fi
if [[ ! $new =~ "@" ]]; then
echo "Invalid new email"
exit 1
fi
# export is mandatory otherwise the git filter-branch
# process can not see these variables
export old
export new
git filter-branch -f --env-filter '
echo "Start -- $old" >> /tmp/no_match.lst
if [[ $GIT_AUTHOR_EMAIL = $old ]]; then
export GIT_AUTHOR_EMAIL=$new
fi
if [[ $GIT_COMMITTER_EMAIL = $old ]]; then
export GIT_COMMITTER_EMAIL=$new
fi
' -- --all
unset old
unset new
# vim: set ai nu nobk expandtab sw=4 ts=4 syntax=sh:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment