Ben Zelnick
Ben Zelnick

Reputation: 522

Resign previous Git commits with a new GPG key

I am trying to transition to a new GPG key. I would like to re-sign all of my previous commits in a Git repository (that have a valid signature with my formerly used key) with the new GPG key.

In other words, how can I automatically resign (with my new key) all of the commits that I signed with my previous key?

If you need key fingerprints to use in your example, please use 0000000000000000000000000000000000000000 as my old GPG key fingerprint and 1111111111111111111111111111111111111111 as my new key fingerprint.

Upvotes: 4

Views: 3306

Answers (1)

VonC
VonC

Reputation: 1324248

You would need to use git filter-branch (as done here), at least:

git filter-branch --commit-filter 'git commit-tree -S "$@"' HEAD

(Probably with a more complex directive, as seen here, if you want to sign only your commits)

The new git filter-repo does not support yet GPG signing (issue 67).

Another approach, also mentioned here, is by using git rebase:

git rebase --exec 'git commit --amend --no-edit -S<keyid>

Upvotes: 3

Related Questions