有可能在本地强制签名提交吗?



我的公司使用GitHub作为我们的组织仓库,并通过强制签名提交来验证作者。

问题是可以克隆一个repo,创建一个分支,提交几个提交,并创建一个Pull Request,而不需要任何签名的提交。直到试图将PR合并到developmain或任何受签名提交保护的分支中,PR合并才会失败。在这一点上,我们必须用rebase来清理它,这样就不会有没有签名的提交。

是否有一种方法来强制签名,甚至在本地克隆的回购?像预提交钩子这样的东西,确保在没有签名的情况下提交失败?一旦设置好,它看起来就像这样:

> git clone <my-company's-git-repo-with-signatures-required-on-main-branch>
> cd <my-company's-git-repo-with-signatures-required-on-main-branch>
> git switch main # Just to make it clear that I am on the protected branch
> touch my-new-file
> git add my-new-file
> git commit -m "Testing" # And this is for a user that does not have signing set up yet.
Git Error: Cannot commit without signature  # Or whatever the error message would be

这可以防止任何类型的"回滚"。通过rebase或任何其他可能的方法。

我认为这是不可能强迫别人创建一个签名提交,或类似的事情做force signed commit检查。

因为这是你的公司存储库,签名提交是必须的。你可能想制定一个规则:任何对这个存储库做出贡献的人都应该做签名提交。

供参考:你可以将normal commit的git别名设置为signed commit

类似:

s-commit = !sh -c 'git commit -S $*'

even make commit always to signed commit..: -)

当然,任何贡献者都应该使用或遵守此规则。

相关内容