Skip to content

Instantly share code, notes, and snippets.

@vermiculus
Last active August 29, 2015 14:06
Show Gist options
  • Save vermiculus/e9abc96db3efc9705add to your computer and use it in GitHub Desktop.
Save vermiculus/e9abc96db3efc9705add to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Usage:
#
# git-unite "User Name" "new@email.com" \
# "old1@email.com" \
# "old2@email.com" \
# ...
name="$1"
email="$2"
git config user.name "$name"
git config user.email "$email"
shift 2
for old_email in $*; do
echo "changing $old_email"
git filter-branch --force --env-filter '
if [ "$GIT_COMMITTER_EMAIL" = "$(echo $old_email)" ]
then
export GIT_COMMITTER_NAME="$(echo $name)"
export GIT_COMMITTER_EMAIL="$(echo $email)"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$(echo $old_email)" ]
then
export GIT_AUTHOR_NAME="$(echo $name)"
export GIT_AUTHOR_EMAIL="$(echo $email)"
fi
' --tag-name-filter cat -- --branches --tags
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment