As mentioned in some other answers you would probably use:
git commit --amend --reset-author --no-edit --date="<old-date>"
While this works it's a lot of manual copying or typing to get the old date in place. You might want to get the date automatically, by getting only the date of the last entry in the log:
git log -n 1 --format=%aD
Combine the two and use some shell magic:
git commit --amend --reset-author --no-edit --date="$(git log -n 1 --format=%aD)"
This automatically sets the date of the last commit in the log, aka the one to be amended, as date of the new commit with the changed author.
Now changing the author on a larger amount of commits, say because you forgot to set the author in the cloned git repo, an interactive rebase is your friend:
git rebase -i <commit before wrong author and email>
You then change all commits you want to adjust from pick
to edit
and save the file. Git stops on every commit to be edited and you rerun:
git commit --amend --reset-author --no-edit --date="$(git log -n 1 --format=%aD)" && \
git rebase --continue
If it's a reasonable small number of commit you can repeat this command using the shells arrow-up
key until until the rebase finishes. If there is a larger number of commits, that typing arrow-up
+ return
becomes too tedious you might want to create a small shell script that repeats the above command until the rebase finishes.