首页 > 解决方案 > 是否可以在本地强制执行签名提交?

问题描述

我的公司将 GitHub 用于我们的组织存储库,并通过强制签名提交来验证作者。

问题是可以克隆一个 repo,创建一个分支,提交多个提交,并创建一个 Pull Request,而无需任何签名的提交。直到尝试将该PR 合并到 PR 合并失败的受签名提交保护的分支developmain任何受签名提交保护的分支。那时,我们必须用 a 清理它,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或任何其他可能的方法。

标签: gitdigital-signaturegit-commitpre-commit-hook

解决方案


我认为这不可能强迫某人创建签名提交,或者类似的事情进行force signed commit检查。

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

仅供参考:您可以做的是将 git 别名设置normal commitsigned commit.

就像是:

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

甚至总是对已签名的提交进行提交.. :-)

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


推荐阅读