如何防止git commit --no-verify命令? [英] How to prevent git commit --no-verify command?

查看:414
本文介绍了如何防止git commit --no-verify命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为所有git repos设置一个预提交钩子,以使用jshint和phplint验证语法错误.但是问题在于git具有可以使用--no-verify标志跳过预提交钩子的功能.但是我不需要使用该选项.我可以阻止git的--no-verify标志吗?请提出一种方法.

I would like to setup a pre-commit hook for all git repos to validate syntax errors using jshint and phplint. But the issue is that the git has a feature which can skip pre-commit hook from happening by using --no-verify flag. But i don't need to use that option. Can i prevent that --no-verify flag for git Please suggest a way.

推荐答案

首先,您不能确定地阻止某人通过--no-verify选项.话虽如此,使用pre-commit挂钩进行掉毛是一种好习惯,避免无故通过--no-verify选项也是一种好习惯.

First off: you can't definitively prevent someone from passing the --no-verify option. That said, it's a good practice to use pre-commit hooks for linting, and it's a good practice to avoid passing the --no-verify option without reason.

但是,如果您希望通过--no-verify选项变得更加麻烦,则可以:

If, however, you want to make it more cumbersome to pass the --no-verify option, you could:

  1. 生成验证令牌并将其附加到pre-commit;
  2. 中的提交消息中 如果缺少此令牌或该令牌无效,则
  3. 以非零退出代码退出pre-receive. (您可以在预接收挂钩中执行的操作示例: https: //github.com/github/platform-samples/tree/master/pre-receive-hooks )
  1. generate a verification token and append it to the commit message in pre-commit;
  2. exit pre-receive with a non-zero exitcode if this token is missing or invalid. (Examples of things you can do in pre-receive hooks: https://github.com/github/platform-samples/tree/master/pre-receive-hooks)

决心避免通过--no-verify的人可以手动执行步骤1,这就是为什么它不是100%有效的原因.我不建议在专业环境中进行设置,但是我只适合那些使用工具的人为他们灌输良好的习惯,同时更多地了解git hooks.

Someone determined to avoid passing --no-verify could manually do step 1, which is why this isn't 100% effective. I wouldn't recommend setting this up in a professional context, but I'm all for people using the tools at their disposal to instill good habits for themselves, while learning more about git hooks.

这篇关于如何防止git commit --no-verify命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆