Switching between work and personal environments can lead to mistakes like this.
I try to automate the switch by having scripts setting up different looks on my terminal for each environment I'm working on. Sometimes I just forget, though. If you're in this situation, you probably forgot something similar not long ago, and are trying to fix it.
Since I never seem to remember the command to change back a git commit author, and google it every time, here is my attempt at remembering it for good by writing a post about it.
The first thing to do is rebasing your git history. You have a couple of choices to enter interactive rebase. My favorite one is using a commit count from
For example, if I want to change the author of the last 3 commits, I can use:
git rebase -i HEAD~3
This will give you a similar list:
pick 42e5f88 Commit #1 pick f0674a1 Commit #2 pick 376b59c Commit #3
For now, just change
edit on the commits you would like to change the author of.
edit 42e5f88 Commit #1 pick f0674a1 Commit #2 edit 376b59c Commit #3
Notice the change on the first and the third commits.
To rebase, you could also use the hash of a commit directly:
git rebase -i 42e5f88
After saving the open git interactive rebase document is when the rebasing actually starts.
Editing commits is an action that happens one commit at a time. So if you chose to edit
n commits, you will need to execute the next commands
git commit --amend --author="Author Name <firstname.lastname@example.org>"
Since you are still rebasing after this command, execute this next command:
git rebase --continue
--continue command will either end the whole rebasing or enter the edit mode for the next commit you need to edit.
Once you have edited all your commits, make your changes live by force pushing them to your repository:
git push --force