Replacing Committer Name and Email on Commits - blitterated/docker-dev-env GitHub Wiki
Have you ever made a series of commits and forgot to change git's local config for your name and email?
Here we'll take a look at how to replace commits with the wrong name and email associated with them.
Tools
Install pipx with brew
brew install pipx
Install git-filter-repo with pipx
pipx install git-filter-repo
Operation
Create a directory to work in and jump into it
This directory will be used to clone a repository into as well as to hold the mailmap
file we'll use to remap the user and email address.
mkdir ~/fix-emails && cd $_
Create a mailmap file in the work directory
If you try to do this in the repo itself, you get the following warning:
this does not look like a fresh clone.
(you have untracked changes)
Please operate on a fresh clone instead. If you want to proceed
anyway, use --force.
The syntax is gitmailmerge.
Proper Name <[email protected]> Commit Name <[email protected]>
Or another way to look at the syntax:
Name-to-change-to <[email protected]> Name-currently-on-commits <[email protected]>
Now create the mailmerge file.
cat > mailmap <<EOF
blitterated <[email protected]> Real Name <[email protected]>
EOF
Pull down a fresh clone of your repo and cd into it
git clone [email protected]:blitterated/some-repo.git
cd some-repo
Run git-filter-repo
git filter-repo --mailmap ../mailmap
Check the results
git log
or tig
if you've got it installed
tig
Change the commiter name and email for this repo
git config user.name "blitterated"
git config user.email "[email protected]"
Push
Add the remote repo
git remote add origin ghblit:blitterated/some-repo.git
Push to remote
git push -u --force origin master
Pull and rebase in other local clones
git pull --rebase