指定要在git commit --no-verify上跳过的钩子 [英] specify which hook to skip on git commit --no-verify

查看:2077
本文介绍了指定要在git commit --no-verify上跳过的钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用--no-verify时是否有一种方法可以确切指定要跳过哪个git-hook?还是有除--no-verify以外的其他标志来完成此操作?也许只是一个标志,仅跳过pre-commit?

If there a way to specify exactly which git-hook to skip when using --no-verify? Or is there another flag other than --no-verify to accomplish this? Perhaps just a flag to only skip pre-commit?

我经常使用两个钩子,分别是pre-commitcommit-msg. pre-commit运行我的棉绒检查,流量检查和一些单元测试. commit-msg将我的分支名称附加到提交消息的末尾.

I have two hooks that I regularly use, pre-commit and commit-msg. pre-commit runs my linting, flow check, and some unit tests. commit-msg appends my branch name to the end of the commit message.

有时候我想--no-verify pre-commit,但仍然想运行commit-msg.

There are times that I would like to --no-verify the pre-commit but would still like to have commit-msg run.

似乎有很多类似的SO帖子,但没有什么比--no-verify选择性跳过更重要的了.

There seem to be a lot of SO posts similar to this, but nothing quite like selective skipping with --no-verify.

推荐答案

跳过

如果您能够修改挂钩,则可以为每个按钮添加一个切换开关.

Skipping

If you are able to modify the hooks, you can add a toggle for each one.

来自 pre-commit.sample :

# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --bool hooks.allownonascii)

因此,要启用切换整个pre-commit 钩子的功能,可以将其添加到 它的开始:

So to enable toggling the entire pre-commit hook, this could be added to the beginning of it:

enabled="$(git config --bool hooks.pre-commit.enabled)"

if test "$enabled" != true
then
    echo 'Warning: Skipping pre-commit hook...'
    exit
fi

用法示例:

git -c hook.pre-commit.enabled=false commit

别名

注意:两种别名

Aliasing

Note: Both types of aliases break tab completion.

git alias 可以简化此操作:

A git alias could simplify this:

git config --global alias.noprecommit \
  '!git -c hook.pre-commit.enabled=false'

这样,您可以通过以下调用来提交并跳过 hook :

With that, you could commit and skip the hook with the following invocation:

git noprecommit commit

您还可以使用 shell alias (在例如:~/.bashrc):

alias gitnoprecommit='git -c hook.pre-commit.enabled=false'

用法示例:

gitnoprecommit commit

这篇关于指定要在git commit --no-verify上跳过的钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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