— git, rebase, git-author, github, code snippet, today-i-learned — 1 min read
So I just realized today that all my commits were made with my previous' company's email. Since I'm in a new place now, figured I should change author email for git.
But I wanted to keep my email private, and luckily GitHub allows that with their noreply feature. Anyway, I realized that all my commits, all the way to the first commit in this project was made with the wrong email. I didn't want to change the actual commit dates, so I looked for a way to change the author name and email while keeping the original commit timestamps.
{ID}+{username}@users.noreply.github.com
.1git config --global user.email "{ID}+{username}@users.noreply.github.com"
If it's just the last commit you wanted to ammend, use this:
1git commit --amend --reset-author
Note that this will update the timestamp of the commit.
HEAD
, then first find the commit's SHA with this:1git log
1git rebase -i <YOUR_SHA> -x "git commit --amend --reset-author -CHEAD"
Note that this will update the commit timestamps.
1git rebase -i YOUR_SHA -x "git commit --amend --author 'New Name <{ID}+{username}@users.noreply.github.com>' -CHEAD"
Note that you have to keep the <>
and only replace the name and email.
1git rebase -i YOUR_SHA -x 'git commit --amend --reset-author --no-edit --date="$(git log -n 1 --format=%aD)"'
Found it from a SO comment