Skip to content

Instantly share code, notes, and snippets.

@eksrha
Last active April 22, 2022 07:50
Show Gist options
  • Save eksrha/3fe5fc58c77969f2f49eb8521fe5c081 to your computer and use it in GitHub Desktop.
Save eksrha/3fe5fc58c77969f2f49eb8521fe5c081 to your computer and use it in GitHub Desktop.
rewrite git committer and author names with alias change-commits

set git alias (windows cmd or linux bash)

git config --global --edit

In the "alias" section:

[alias]
       change-commits = "!f() { VAR=$1; OLD=$2; NEW=$3; shift 3; git filter-branch --env-filter \"if [ \\\"$`echo $VAR`\\\" = '$OLD' ]; then export $VAR='$NEW'; fi\" $@; }; f "

check result

git config --global alias.change-commits
# !f() { VAR=$1; OLD=$2; NEW=$3; shift 3; git filter-branch --env-filter "if [ \"$`echo $VAR`\" = '$OLD' ]; then export $VAR='$NEW'; fi" $@; }; f

list all authors

git shortlog -sne

change git author email

change to hidden github-mail https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-user-account/managing-email-preferences/setting-your-commit-email-address#setting-your-commit-email-address-on-github

git change-commits GIT_AUTHOR_EMAIL '[email protected]' '[email protected]'

change username

git change-commits GIT_AUTHOR_NAME 'Long Wrong Name' 'shorty'

you can also change the committer data

git change-commits GIT_COMMITTER_NAME 'OLD' 'NEW'
git change-commits GIT_COMMITTER_EMAIL 'OLD' 'NEW'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment