Is there a way to remove gpg sign of all previous commits or resign it with another gpg key

Viewed 602

I have just lost my old gpg key by accident. I'm wondering if I can remove each commit's gpg sign or resign it with my new gpg key?

1 Answers

I know this is an old question but i came across a similiar situation where i had to sign(re-sign actually) bunch of old commits. First confirm how many of the previous commits you want to (re)sign:

git log --show-signature

Suppose you want to sign the previous 5 commits then you can do:

git rebase -i HEAD~5

In the editor you will see your commits:

...
pick 4dd9ec5 fixed wrong config
pick 89d21f4 minor fix
...

Just add this line after every commit that you want to sign(re-sign).

exec git commit --amend --no-edit -s

So it would look like :

...
pick 4dd9ec5 fixed wrong config
exec git commit --amend --no-edit -s
pick 89d21f4 minor fix
exec git commit --amend --no-edit -s
...

Save and exit:

NOTE: Make sure you have force push priviledge (git push -f) in the upstream repository because this most likely would require to push with all force.

ANOTHER NOTE: With this method you can sign all but one previous commit. You may not be able to sign your initial commit.

Source

Edit: the source is not available anymore. So this is what it is.

Related