Skip to content

Instantly share code, notes, and snippets.

@alexander-bauer
Created October 16, 2012 00:55
Show Gist options
  • Save alexander-bauer/3896675 to your computer and use it in GitHub Desktop.
Save alexander-bauer/3896675 to your computer and use it in GitHub Desktop.
git authorship and email adjustment
#!/bin/sh
# This script uses git filter-branch to adjust author names and
# emails. No success is garuenteed. Usage is as follows:
#
# gitfix.sh --name|--email oldValue newValue
#
OLDVALUE=$2
NEWVALUE=$3
if [ "$1" != "--name" ] && [ "$1" != "--email" ]
then
echo "usage: $0 option oldValue newValue
options:
--name adjust GIT_AUTHOR_NAME and GIT_COMMITTER_NAME
--email adjust GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL"
fi
if [ "$1" = "--name" ]
then
git filter-branch -f --env-filter "
if [ \"\$GIT_AUTHOR_NAME\" = \"$OLDVALUE\" ]
then
export GIT_AUTHOR_NAME=\"$NEWVALUE\"
fi
if [ \"\$GIT_COMMITTER_NAME\" = \"$OLDVALUE\" ]
then
export GIT_COMMITTER_NAME=\"$NEWVALUE\"
fi
" HEAD
elif [ "$1" = "--email" ]
then
git filter-branch --env-filter "
if [ \"\$GIT_AUTHOR_EMAIL\" = \"$OLDVALUE\" ]
then
export GIT_AUTHOR_EMAIL=\"$NEWVALUE\"
fi
if [ \"\$GIT_COMMITTER_EMAIL\" = \"$OLDVALUE\" ]
then
export GIT_COMMITTER_EMAIL=\"$NEWVALUE\"
fi
" HEAD
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment