Changing the git author for previous commits

Every now and then, after putting in a few commits, I realize that I am using the wrong author or email for my git project. This can happen if you dont set your git config correctly and it picks up the global username and email. To fix that, you gotta change history. Here’s how its done.

Given an example commit history of A-B-C-D-E-F, and assuming you want to change the author of commits C, D and E, do the following

Step 1: 
git rebase -i B
Step 2:
change the lines for C, D and E to `e` or `edit`
Step 3: 
rebase will start at C
Step 4: 
git commit --amend --no-edit --author="Author Name <[email protected]>"
Step 5:
git rebase --continue

Repeat steps 4 and 5 until you are done.

References

https://stackoverflow.com/a/3042512/226953

Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...