6

My local commits have wrong email so I used the following command to reset it. However, it only reset the latest local commit. How to reset the earlier ones?

git commit --amend --reset-author --no-edit
ca9163d9
  • 27,283
  • 64
  • 210
  • 413
  • Maybe just try to checkout earlier (or any other that you want to amend) commit and then execute this. – ulou Oct 14 '20 at 16:54

2 Answers2

11

Assuming you have a linear history, you can reset the authorship of all commits with

git rebase -i --exec 'git commit --amend --reset-author --no-edit' --root

If only a subset of commits is affected, which still must be all in a linear history, replace --root with the commit ID before the first one of yours.

j6t
  • 9,150
  • 1
  • 15
  • 35
3

Do (you may need to increase/decrease 20 according to how far back the commit you want to edit is):

git rebase -i HEAD~20

and, for the commit you want to amend, replace pick with edit (in the interactive window). Save, and close.

Then, do git commit --amend, make your change, and let the rebase continue.

ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65