Created
April 25, 2017 13:52
-
-
Save dominickm/a873f9d6e5ea3910fa40d43f8883affa to your computer and use it in GitHub Desktop.
Removes instances of one user and replaces them with another in a Git history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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