Skip to content

Instantly share code, notes, and snippets.

@MrSwed
Forked from octocat/git-author-rewrite.sh
Last active August 29, 2015 14:17
Show Gist options
  • Save MrSwed/44fba0b318b239618b61 to your computer and use it in GitHub Desktop.
Save MrSwed/44fba0b318b239618b61 to your computer and use it in GitHub Desktop.
#!/bin/sh
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ ! -n "$oemail" ]
then
oemail="$OLD_EMAIL"
fi
if [ ! -n "$author" ]
then
author="$CORRECT_NAME"
fi
if [ ! -n "$email" ]
then
email="$CORRECT_EMAIL"
fi
usagetip="
Changing author info in git history.
https://help.github.com/articles/changing-author-info/
Use CTRL-C to exit
Usage:
$0 \\
-oemail $oemail \\
-author $author \\
-email $email
"
if [ ! -n "$1" ]
then
echo "$usagetip"
fi
while echo $1 | grep -q ^-; do
if [[ "$1" = "-help" || "$1" == "-h" ]]
then
help=1
shift
else
eval $( echo $1 | sed 's/^-//' )=\"$2\"
shift
shift
fi
done
if [[ -n $help ]]
then
echo "$usagetip"
fi
echo "
Confirm that all right (enter to confirm or write correct new one, ctrl-c cancel): "
for carg in oemail author email
do
eval curval=\$$carg
read -p " -$carg '$curval': " varconfirm
if [ -n "$varconfirm" ]
then
eval export $carg=$varconfirm
eval echo " Ok. Now -$carg is \'\$$carg\'"
fi
done
echo '
Ok. Start git filter-branch for '$oemail' => '$author' <'$email'>'
git filter-branch --env-filter '
OLD_EMAIL="'"$oemail"'"
CORRECT_NAME="'"$author"'"
CORRECT_EMAIL="'"$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