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

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

问题描述

我想为所有 git 存储库设置一个预提交挂钩,以使用 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 钩子进行 linting 是一个好习惯,避免无缘无故传递 --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天全站免登陆