Last active
January 17, 2018 11:41
-
-
Save Leandros/376a0c481259ee94cb2efc22da421fa8 to your computer and use it in GitHub Desktop.
Rewrite git author
This file contains hidden or 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
#!/bin/bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
VERSION=$(git --version | cut -b13- | sed -n 's/.*[0-9]*\.\([0-9]*\)\.[0-9]*.*/\1/p') | |
if [ "$VERSION" -lt 15 ]; then | |
echo "git version 2.15.0 or higher required" | |
echo "please upgrade your git: brew upgrade git" | |
exit 1 | |
fi | |
############################################################################## | |
# CONFIG | |
############################################################################## | |
MASTER="master" | |
OLDMAIL="[email protected]" | |
################################################################################ | |
## Here be dragons. Seriously, this is dark magic. | |
if [ "$1" = "" ]; then | |
echo "usage: fix.sh PATH" | |
echo "" | |
fi | |
branch=$(git -C $1 rev-parse --abbrev-ref HEAD) | |
git -C $1 filter-branch -f \ | |
--setup \ | |
" | |
oldmail=\"$OLDMAIL\" | |
newname=\"$(git -C $1 config user.name)\" | |
newmail=\"$(git -C $1 config user.email)\" | |
branch=$(git -C $1 rev-parse --abbrev-ref HEAD) | |
" \ | |
--env-filter \ | |
' | |
if [ "$GIT_COMMITTER_EMAIL" = "$oldmail" ]; then | |
export GIT_COMMITTER_NAME="$newname" | |
export GIT_COMMITTER_EMAIL="$newmail" | |
fi | |
if [ "$GIT_AUTHOR_EMAIL" = "$oldmail" ]; then | |
export GIT_AUTHOR_NAME="$newname" | |
export GIT_AUTHOR_EMAIL="$newmail" | |
fi | |
' --tag-name-filter cat -- $MASTER..$branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment