git - change the signature of a signed commit
December 12, 2024
Change the signature of the last commit:
$ git commit --amend --no-edit -n -S <keyid>
--amend: Replace the tip of the current branch by creating a new commit.
--no-edit: Use the selected commit message without launching an editor. The commit message won't change.
-n: Bypass the pre-commit and commit-msg hooks.
-S: [--gpg-sign]: GPG-sign commits. The keyid argument is optional and defaults to the committer identity[.]
# Example:
$ git commit --amend --no-edit -n -S D7E9F238FD9F7A68BBA4F57AA59953E41FEBB5F2
# Note: The <keyid> is optional.
Change the signature of older commits:
- Interactively
git rebase
everything untilmy_branch
(or any hash). --exec
is applied to each and every commit in the range.
$ git rebase --exec 'git commit --amend --no-edit -n -S' -i my_branch
- The result of the above one-liner can also be accomplished in a more manual manner:
$ git rebase -i my_branch
pick 12345 commit message
exec git commit --amend --no-edit -n -S
pick 67890 commit message
exec git commit --amend --no-edit -n -S
Always sign commits: * Add to the git configuration:
$ git config commit.gpgsign true
- A
gpg
configuration could look like this - including a specific gpg key:
$ git config -l
...
user.signingkey=A17BEB9EBF763280A57B0C8DA7F8A1CFB1B0FDH4
commit.gpgsign=true
...
Helpful commands:
$ git log --show-signature