There was one method that didn't get mentioned yet, but in effect it equates to an interactive rebase with edit
on each commit to-be-signed and a manual amend/commit (with -S
), but with a predetermined command and in an automated fashion:
git rebase --exec 'git commit --amend --no-edit -S' HEAD~3
The -i
(--interactive
) is implied with --exec
given, according to the documentation, so it's not given above.
Here we rebase against HEAD~3
as in the question, and git commit --amend --no-edit -S
each of the commits. This should usually ask for the passphrase of the PGP key once and then rush through for the remaining commits.
NB: it should go without saying, but since it was commented: just as with the other methods you'll only want to do that with your own commits. Remove the --no-edit
and you'll be dropped into the editor, showing (in a comment at the bottom) what changes you're dealing with. This way you can verify that the commits are yours (unless you already did by way of git log
or so).
Arguably to tell Git to sign when you haven't configured it globally, you could probably also use git -c commit.gpgSign=true
(or other related configuration options) in the command passed via --exec
.