Skip to content

Instantly share code, notes, and snippets.

@fernandomora
Created September 12, 2016 22:40
Show Gist options
  • Save fernandomora/562a83be848b8867d24ed321cc6f5741 to your computer and use it in GitHub Desktop.
Save fernandomora/562a83be848b8867d24ed321cc6f5741 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# see https://help.github.com/articles/changing-author-info/
NAME=`basename ${BASH_SOURCE[0]}`
DESCRIPTION="Change any commits that previously had the old email address in its author or committer fields to use the correct name and email address."
# Define help function
function help(){
if [[ -z "$1" ]]; then echo "${NAME}: ${DESCRIPTION}"; else echo ${NAME}: $1; fi
# echo "${NAME} - ${DESCRIPTION}";
echo "Usage example: ${NAME} -o value -n value -e value";
echo "Options:";
echo " -o: OLD_EMAIL. Required.";
echo " -n: CORRECT_NAME. Required.";
echo " -e: CORRECT_EMAIL. Required.";
exit 1;
}
while getopts ":o:n:e:h" optname
do
case "$optname" in
"h")
help
;;
"o")
OLD_EMAIL=$OPTARG
;;
"n")
CORRECT_NAME=$OPTARG
;;
"e")
CORRECT_EMAIL=$OPTARG
;;
"?")
help "Invalid option: -$OPTARG"
;;
":")
help "Option -$OPTARG requires an argument."
;;
*)
help "Unknown error while processing options"
;;
esac
done
shift $((OPTIND-1))
# Check required arguments
if [[ -z "$OLD_EMAIL" ]]; then help "Option -o is required"; fi
if [[ -z "$CORRECT_NAME" ]]; then help "Option -n is required"; fi
if [[ -z "$CORRECT_EMAIL" ]]; then help "Option -e is required"; fi
echo \'$OLD_EMAIL\' \'$CORRECT_NAME\' \'$CORRECT_EMAIL\'
git filter-branch --env-filter $'
OLD_EMAIL="'$OLD_EMAIL$'"
CORRECT_NAME="'$CORRECT_NAME$'"
CORRECT_EMAIL="'$CORRECT_EMAIL$'"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment