Changing the author info of previous commits in Git

The problem is that you forgot to change the email to your work email before you commit your code, so you’re exposing your personal email. How to change it?

git filter-branch

So the solution is to make use of git filter-branch sub-command. I know what you’re thinking, you don’t want to learn yet another command line tools and just want to get things done? Okay, me too.

A script that do the job

Please download this scripts from the GitHub help section that help you modify the user info of commits. For convenience I also copy it here:

  1. Save this script inside your project directory, name it whatever your like, e.g. git-author-rewrite.sh
  2. change the OLD_EMAIL, CORRECT_NAME and CORRECT_EMAIL respectively
  3. To run the script:
    $   chmod +x git-author-rewrite.sh
    $   ./git-author-rewrite.sh
  4. Push to the remote using this command:
    $    git push –force –tags origin ‘refs/heads/*’
  5. then you can remove the git-author-rewrite.sh

Have fun and good luck!

Reference

Share your thoughts