Skip to content

Instantly share code, notes, and snippets.

@jbouse
Created March 2, 2016 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbouse/7c01cc7266f6aa4cf388 to your computer and use it in GitHub Desktop.
Save jbouse/7c01cc7266f6aa4cf388 to your computer and use it in GitHub Desktop.
Found online, can't recall source to give credit
#!/bin/bash
#
# Changes author and committer name and email throughout the whole repository.
# Uses a file with the following format:
#
# john.doe@hotmail.com=John Doe <john.doe@hotmail.com>
# jill.doe@hotmail.com=Jill Doe <jill.doe@hotmail.com>
#
if [ ! -e "$1" ]
then
echo "File '$1' does not exist"
exit 1
fi
export authors_file=$1
git filter-branch -f --env-filter '
grep "^$GIT_COMMITTER_EMAIL=" "$authors_file" >> /dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ]
then
get_name () {
grep "^$1=" "$authors_file" |
sed "s/^.*=\(.*\) <.*>$/\1/"
}
get_email () {
grep "^$1=" "$authors_file" |
sed "s/^.*=.* <\(.*\)>$/\1/"
}
name=$(get_name "$GIT_COMMITTER_EMAIL")
email=$(get_email "$GIT_COMMITTER_EMAIL")
GIT_AUTHOR_NAME="$name" &&
GIT_AUTHOR_EMAIL="$email" &&
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" &&
GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
fi
' -- --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment