3

I accidentally made a few (about 20) commits to my local, unpushed Git repository under a different GPG key, email, name, etc. How do I resign/reauthor all of the commits under another configuration?

An answer that reauthors all commits would be fine because all the commits are authored by me, but a solution that can target a certain author would be good too.

Bash scripts would work, but I'm on Windows currently. I'd have to open WSL and run the bash script from there. An answer in PowerShell would be appreciated as it's cross-platform. If it can be done in a single Git command that'd also be excellent. Thanks.

Kot
  • 445
  • 4
  • 9
  • 4
    If using the linked answer, you can go with `git filter-branch` and specifying the unpushed commit range (`@{u}..@`) that would not change entire history. If I'd like to make it simply and quickly (especially that `filter-branch` is pretty complex), I'd run interactive rebase for the commit range, replace `pick`s with `edit`s, and then run `git commit --amend --reset-author --no-edit && git rebase --continue` until the rebase is completed. – terrorrussia-keeps-killing Dec 17 '20 at 07:13
  • 4
    @fluffy : or use the `-x` option to rebase : `git rebase -i ... -x "git commit --amend --reset-author --no-edit"` – LeGEC Dec 17 '20 at 07:47
  • @LeGEC Awesome! I really used to think that `--interactive` always requires a TODO-sequence only, hence nothing is assumed to specify the sequence via the command line. Now I see that `-x` fits the case just perfect, hence even `-i` is not that necessary here. Glad to know a new thing on git everyday. Thank you for the suggestion! – terrorrussia-keeps-killing Dec 18 '20 at 10:25

1 Answers1

5

The current option (in python, equally cross-platform) is to use git filter-repo, which replaces the old obsolete git filter-branch or BFG

It comes with User and email based filtering and works with one line:

git filter-repo --mailmap my-mailmap

with my-mailmap:

Correct Name <correct@email.com> <old@email.com>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250