How to change author and email into a GIT commit

Renán Romero
3 min readJan 30, 2019

--

When you work at home, office or in another workstation, etc. Maybe we’ll forget set the username and email on the project. Once you did commit to repo from that station. Appears in GitHub in this way:

Here we can see the username and email not is equal to GitHub credential. Dammit! So we going to change the author for the correct username and email.

This should make into a local clone.

We proceed to watch the hashes

git log

Get the previous hash and rebase

Now, we will be to proceed to fix these commit. We to go execute a rebase interactive command with the hash to edit:

git rebase -i hash

So, open vim editor, here we go to change pick to edit. This is to change data of our commit.

Appears messages to follow the steps, so we execute the next command:

git commit --amend --author=”Your name <yourname@domain.com>”

Appears vim, there you should exit (:x)

And continue rebase:

git rebase --continue

Then the response will appears:

Successfully rebased and updated refs/heads/master.

It’s the moment that you can review again:

Yes!! That is, now we changed the author in our commit from the project. Now we can a push force to GitHub.

git push origin +master

or

git push origin master --force

And now, our change is reflected at GitHub.

That is! Our author commit and hash is changed, with this tech we can modify one or any data from any commit. You can edit simultaneous commits, only change from pick to edit command at mode interactive rebase. Follow the sequence when opens vim editor.

This is my first post. I hope that helps you. A question, you can write me or follow me in twitter: @renanromero

Thanks for reading!

--

--

Renán Romero
Renán Romero

Written by Renán Romero

Songwriter, working on the web in my free time…

No responses yet