specify which hook to skip on git commit --no-verify

我是研究僧i 提交于 2019-12-06 13:34:53

Skipping

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

Example of a specific validation toggle from pre-commit.sample:

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

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

Usage example:

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

Aliasing

Note: Both types of aliases break tab completion.

A git alias could simplify this:

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

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

git noprecommit commit

You could also use a shell alias (in e.g.: ~/.bashrc):

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

Usage example:

gitnoprecommit commit
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!