Git, rewrite previous commit usernames and emails
git
Solution
You can add this alias:
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"
To change the author name:
git change-commits GIT_AUTHOR_NAME "old name" "new name"
or the email for only the last 10 commits:
git change-commits GIT_AUTHOR_EMAIL "old@email.com" "new@email.com" HEAD~10..HEAD
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"
Source: https://github.com/brauliobo/gitconfig/blob/master/configs/.gitconfig
Problem
I've committed a bunch of commits to a project on Github, however I realized I hadn't set up the proper email and committer full name on the computer I'm currently using to make my commits and therefore the users avatar and email address are not there. How can I rewrite all past commit email and usernames?
Related problems
- Running filter-branch over a range of commits
- Purging file from Git repo failed, unable to create new backup
- How do I change the author and committer name/email for multiple commits?
- Remove refs/original/heads/master from git repo after filter-branch --tree-filter?
- Changing git author info on all commits worked on one of my repos but not the others, why?
- Does GitHub consider .mailmap for contribution graph