How to retain commit gpg-signature after interactive rebase squashing?

10,503

Solution 1

Like Cupcake stated, you can't retain the old signature from the unsquashed commits, but you can sign the new squashed commit if you rebase like this:

git rebase --interactive [email protected] HEAD~4

Adding [email protected] as an argument will sign the final squashed commit.

Solution 2

To reinforce the fact you don't keep signature on rebased commits, git 2.9.x+ (Q3 2016) will clearly state that a git pull --rebase would not check signature (since the rebase part would lost them)

See commit c57e501 (20 May 2016) by Alexander Hirsch (``).
(Merged by Junio C Hamano -- gitster -- in commit 73bc4b4, 20 Jun 2016)

pull: warn on --verify-signatures with --rebase

git-pull silently ignores the --verify-signatures option when running --rebase, potentially leaving users in the belief that the rebase operation would check for valid GPG signatures.

Implementing --verify-signatures for git rebase was talked about, but doubts for a valid workflow rose up. Since you usually merge other's branches into your branch you might have an interest that their side has a valid GPG signature.

Rebasing, on the other hand, is to rebuild your branch on top of other's work, in order to push the result back, and it is too late to reject their work even if you find their commits lack acceptable signature.

Let's warn users that the --verify-signatures option is ignored during "pull --rebase"; users do not wonder what would happen if their commits lack acceptable signature that way.

Solution 3

One option is to set a commit.gpgSign setting to true. This will always sign the commits including the rebased commits.

To do it locally in a repo:

git config commit.gpgSign true

To do it globally:

git config --global commit.gpgSign true
Share:
10,503
Alexander Yancharuk
Author by

Alexander Yancharuk

Go, PHP, MySQL, HighLoad architecture, NoSQL, HTTP.

Updated on June 07, 2022

Comments

  • Alexander Yancharuk
    Alexander Yancharuk about 2 years

    When I want to squash some commits by interactive rebase:

    git rebase -i HEAD~3
    

    And then:

    pick cbd03e3 Final commit (signed)
    s f522f5d bla-bla-bla (signed)
    s 09a7b7c bla-bla (signed)
    
    # Rebase c2e142e..09a7b7c onto c2e142e
    ...
    

    The final commit haven't gpg-signature despite that all of those commits have same signature. Is it possible to retain commit gpg-signature after interactive rebase squash?