Wednesday, July 6, 2022

GIT: Replace username and email from all commits

 1- Create a file custom-name.sh with the following code:

#!/bin/sh

git filter-branch -f --env-filter '
OLD_EMAIL="xxxxxxxxxxxxxxxxxxxxxxxxxx"
CORRECT_NAME="zzzzzzzzzzzzzzzzz"
CORRECT_EMAIL="yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
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
'  HEAD
2- Just replace
OLD_EMAIL="your old email goes here" CORRECT_NAME="your name goes here" CORRECT_EMAIL="new email goes here"
3- Put this file at the root of your project
4- In you GIT bash/shell, run: sh custom-name.sh
5- Push changes to remote branch 
And that's it! 

No comments:

Post a Comment