From 7432d6dd968b44453051f4d8fa85d977b5d0b517 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Wed, 6 Jul 2016 14:27:41 +0200 Subject: [PATCH] Use github script to change commit's author https://help.github.com/articles/changing-author-info/ --- change_git_user.sh | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/change_git_user.sh b/change_git_user.sh index adacdf8..fd96383 100755 --- a/change_git_user.sh +++ b/change_git_user.sh @@ -1,13 +1,22 @@ #!/bin/sh -git filter-branch --commit-filter ' -if [ "$GIT_COMMITTER_NAME" = "OLD_USERNAME" ]; +git filter-branch --env-filter ' +OLD_EMAIL="old_username@email" +CORRECT_NAME="LastName FirstName" +CORRECT_EMAIL="username@email" +if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] then - GIT_COMMITTER_NAME="NEW_USERNAME"; - GIT_AUTHOR_NAME="NEW_USERNAME"; - GIT_COMMITTER_EMAIL="EMAIL_NEW_USERNAME"; - GIT_AUTHOR_EMAIL="EMAIL_NEW_USERNAME"; - git commit-tree "$@"; -else - git commit-tree "$@"; -fi' HEAD + 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 + +printf '%b' "You can check you git history, then run :\n" +printf '%b' "git push --force --tags origin 'refs/heads/*'" + +exit 0