Search code examples
gitgit-commitgit-rewrite-history

Change git email for previous commits


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 (nameofMyComputer@kevin.local) 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 "newemail@example.com"

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 How do I change the author and committer name/email for multiple commits? and used this

 git filter-branch -f --env-filter "                         
                    GIT_AUTHOR_EMAIL='newemail@example.com'; 
                    GIT_COMMITTER_EMAIL='newemail@example.com';
                    " 
                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


Solution

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

    git rebase -i HEAD~40 -x "git commit --amend --author 'Author Name <author.name@mail.com>' --no-edit"
    

    I worked this out better in this answer.