Skip to content

Instantly share code, notes, and snippets.

@codeaid
Last active February 12, 2016 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeaid/03ec04e9ce1d63fa9f34 to your computer and use it in GitHub Desktop.
Save codeaid/03ec04e9ce1d63fa9f34 to your computer and use it in GitHub Desktop.
Update git commit names and emails
#
# More information @ http://schacon.github.io/git/git-filter-branch.html
#
# Rewrite using environment filter
git filter-branch --env-filter \
'if [ $GIT_COMMITTER_EMAIL = old@email.com ];
then
GIT_COMMITTER_NAME="New Name";
GIT_COMMITTER_EMAIL=new@email.com;
GIT_AUTHOR_NAME="New Name";
GIT_AUTHOR_EMAIL=new@email.com;
fi;
export GIT_COMMITTER_NAME;
export GIT_COMMITTER_EMAIL;
export GIT_AUTHOR_NAME;
export GIT_AUTHOR_EMAIL;' \
-f
# Rewrite using commit filter
git filter-branch --commit-filter \
'if [ "$GIT_COMMITTER_EMAIL" = "old@email.com" ];
then
export GIT_AUTHOR_NAME="New Name";
export GIT_AUTHOR_EMAIL=new@email.com;
export GIT_COMMITTER_NAME="New Name";
export GIT_COMMITTER_EMAIL=new@email.com;
fi;
git commit-tree "$@"'
# Only rewrite the name
git filter-branch --commit-filter \
'if [ "$GIT_COMMITTER_NAME" = "Old Name" ];
then
export GIT_AUTHOR_NAME="New Name";
export GIT_COMMITTER_NAME="New Name";
fi;
git commit-tree "$@"'
# Only rewrite the email
git filter-branch --commit-filter \
'if [ "$GIT_COMMITTER_EMAIL" = "old@email.com" ];
then
export GIT_AUTHOR_EMAIL=new@email.com;
export GIT_COMMITTER_EMAIL=new@email.com;
fi;
git commit-tree "$@"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment