Change git email for previous commits

Kevin Cohen picture Kevin Cohen · Jan 18, 2016 · Viewed 13.9k times · Source

So I read a lot about how to change previous commit's email address but for some reason mine is not updating.

I did like 40 commits to my private repo with my local email ([email protected]) which is bad since this email is not associated(and it can't be) with github.

I then remembered that I needed to set the git.config before and so I did:

 git config user.email "[email protected]"

and did a test commit and it worked perfectly.

Is there a way I can revert all my previous commits to this new email?

I read this question on SO Change the author and committer name and e-mail of multiple commits in Git and used this

 git filter-branch -f --env-filter "                         
                    GIT_AUTHOR_EMAIL='[email protected]'; 
                    GIT_COMMITTER_EMAIL='[email protected]';
                    " 
                HEAD

But it DID NOT work... I can still see the email of my previous commits with the .patch extension as the .local email address

Answer

Chris Maes picture Chris Maes · Jan 18, 2016

You can indeed do his for many commits at once like this:

git rebase -i HEAD~40 -x "git commit --amend --author 'Author Name <[email protected]>' --no-edit"

I worked this out better in this answer.