Changing the git author for previous commits

Every now and then, after putting in a few com­mits, I real­ize that I am using the wrong author or email for my git project. This can hap­pen if you dont set your git con­fig cor­rectly and it picks up the global user­name and email. To fix that, you gotta change his­tory. Here’s how its done.

Given an exam­ple com­mit his­tory of A-B-C-D-E-F, and assum­ing you want to change the author of com­mits 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 <author@email.com>"
Step 5:
git rebase --continue

Repeat steps 4 and 5 until you are done.

Ref­er­ences

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...