0

I want to fix the email in the 10 most recent git commits (while keeping the timestamp when they were originally committed, like git rebase does).

Alas, I cannot use --reset-author because it also resets the timestamp.

I suppose I can use git format-patch, then use sed to fix the email, and then git am to apply them.

Is there an easier way?

sds
  • 58,617
  • 29
  • 161
  • 278
  • Which timestamp are you concerned about? – evolutionxbox Feb 22 '22 at 16:51
  • I want to keep the date when each patch was originally committed. – sds Feb 22 '22 at 16:52
  • Commit timestamps are uniquely generated for each commit. I don't think you can manipulate them? – evolutionxbox Feb 22 '22 at 16:53
  • I am pretty sure `git rebase` allows me to modify commits while keeping timestamps. – sds Feb 22 '22 at 16:54
  • You can set explicit committer and author dates using the `GIT_COMMITTER_DATE` and `GIT_AUTHOR_DATE` environment variables. Doing this with multiple commits will probably require a little scripting but should be possible. – larsks Feb 22 '22 at 17:58

2 Answers2

1

Well, it turns out I just had to do something similar. It looked a bit like this:

git rebase HEAD~4 -x 'GIT_AUTHOR_DATE="$(git  show --format=%ad -s)" GIT_COMMITTER_DATE="$(git show --format=%cd -s)" git commit --amend -CHEAD --author "Bob <bob@example.com>"'

This resets the author to "Bob bob@example.com" on the most recent 4 commits, preserving both the committer and author dates.

sds
  • 58,617
  • 29
  • 161
  • 278
larsks
  • 277,717
  • 41
  • 399
  • 399
0

Git filter-repo is probably the best tool for this! Construct a mailmap like so:

Old Name <old-email@stuff.com> Correct Name <your-email@stuff.com>

Save this in a file called mailmap.txt or something (it can be named anything).

Then, run git filter-repo in a fresh clone:

git filter-repo --mailmap path/to/mailmap.txt
Alecto Irene Perez
  • 10,321
  • 23
  • 46