【问题标题】:Resign previous Git commits with a new GPG key使用新的 GPG 密钥退出之前的 Git 提交
【发布时间】:2021-06-24 21:05:06
【问题描述】:

我正在尝试转换到新的 GPG 密钥。我想用新的 GPG 密钥重新签署我以前在 Git 存储库中的所有提交(具有我以前使用的密钥的有效签名)。

换句话说,我怎样才能自动退出(用我的新密钥)我用我以前的密钥签署的所有提交?

如果您需要在示例中使用密钥指纹,请使用 0000000000000000000000000000000000000000 作为我的旧 GPG 密钥指纹,并使用 1111111111111111111111111111111111111111 作为我的新密钥指纹。

【问题讨论】:

    标签: git security digital-signature git-commit gnupg


    【解决方案1】:

    您至少需要使用git filter-branch(如done here):

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

    (可能使用更复杂的指令,如seen here,如果您只想签署您的提交)

    新的git filter-repo 尚不支持 GPG 签名 (issue 67)。

    另一种方法,也是mentioned here,是使用git rebase

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

    【讨论】:

    • 您能详细说明一下吗?我将如何辞职 main 分支上的所有提交?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    相关资源
    最近更新 更多