Skip to content

Instantly share code, notes, and snippets.

@zaz
Last active September 23, 2018 09:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaz/384d85a2832dcce5cffc136c2b6cdb4e to your computer and use it in GitHub Desktop.
Save zaz/384d85a2832dcce5cffc136c2b6cdb4e to your computer and use it in GitHub Desktop.
If you accidentally make some commits with your email (or name) set incorrectly, this script fixes it. With no arguments, it updates all commits with your name to use your email address according to Git config. Don't use this on a branch you're collaborating on.
DEFAULT_NAME="$(git config user.name)"
DEFAULT_EMAIL="$(git config user.email)"
export OLD_NAME="${1:-$DEFAULT_NAME}"
export NEW_NAME="${2:-$DEFAULT_NAME}"
export NEW_EMAIL="${3:-$DEFAULT_EMAIL}"
echo "Old:" $OLD_NAME "<*>"
echo "New:" "$NEW_NAME <$NEW_EMAIL>"
echo "To undo, use: git reset $(git rev-parse HEAD)"
git filter-branch --env-filter \
'if [ "$GIT_AUTHOR_NAME" = "${OLD_NAME}" ]; then
export GIT_AUTHOR_NAME="${NEW_NAME}"
export GIT_AUTHOR_EMAIL="${NEW_EMAIL}"
export GIT_COMMITTER_NAME="${NEW_NAME}"
export GIT_COMMITTER_EMAIL="${NEW_EMAIL}"
fi'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment