I have made a series of commits in Git and I realise now that I forgot to set my user name and user email properties correctly (new machine). I have not yet pushed these commits to my repository, so how can I correct these commits before I do so (only the 3 latest commits on the master branch)?
I have been looking at git reset
and git commit -C <id> --reset-author
, but I don't think I'm on the right track.
Rebase/amend seems inefficient, when you have the power of filter-branch at your fingertips:
git filter-branch --env-filter 'if [ "$GIT_AUTHOR_EMAIL" = "incorrect@email" ]; then
GIT_AUTHOR_EMAIL=correct@email;
GIT_AUTHOR_NAME="Correct Name";
GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL;
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; fi' -- --all
(split across lines for clarity, but not necessary)
Be sure to inspect the result when you're done, to make sure that you didn't change anything you didn't mean to!