Fix incorrect GIT author for multiple commits

I have separate GIT identities for my personal and client coding, and sometimes I’ve been working on a new codebase for a while under the wrong identity without noticing. This can be super fiddly to fix on a per-commit basis with the command line.

Here is a blunt-force way to change ALL of your personal commits to match your work account, without affecting other contributor history. ALWAYS make a copy of your project folder before attempting this kind of surgery as it can blat your entire repo history.

➜ git config user.email
[email protected] # oops wrong identity
➜ git config user.name "My Name"
➜ git config user.email "[email protected]"
➜ git filter-branch --env-filter 'if [ "$GIT_AUTHOR_EMAIL" = "[email protected]" ]; then [email protected]; GIT_AUTHOR_NAME="My Name"; GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL; GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; fi' -- --all

(read the scary warning and press <enter>)

Proceeding with filter-branch…
Rewrite 0ba49ecf8d03eacdbe082cbc6616c528efa7e839 (2263/2268) (164 seconds passed, remaining 0 predicted)
Ref 'refs/heads/develop' was rewritten
Ref 'refs/heads/feature/my-feature' was rewritten

I recommend immediately pushing to your remote repo and checking that the commit history looks ok so you can roll back if needed.

Leave a comment