Skip to content

Instantly share code, notes, and snippets.

@pedrosancao
Last active August 6, 2020 19:40
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 pedrosancao/8e0a3ae6e8d3aca9f015dbaa8991940a to your computer and use it in GitHub Desktop.
Save pedrosancao/8e0a3ae6e8d3aca9f015dbaa8991940a to your computer and use it in GitHub Desktop.
Fix commit author because I keep commiting with my company e-mail on personal projects
#!/bin/bash
if [ -z $1 ]; then
echo "Usage $0 LAST_CORRECT_COMMIT"
exit 0
fi
git filter-branch --env-filter 'export GIT_COMMITTER_NAME="Pedro Sanção"; export GIT_COMMITTER_EMAIL="pedrosancao@users.noreply.github.com"; export GIT_AUTHOR_NAME="Pedro Sanção"; export GIT_AUTHOR_EMAIL="pedrosancao@users.noreply.github.com"; export GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"' $1..HEAD
# sample with ifs from https://stackoverflow.com/a/61765245/2932525
# OLD_EMAIL="your-old-email@example.com"
# CORRECT_NAME="Your Correct Name"
# CORRECT_EMAIL="your-correct-email@example.com"
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment