[英]Git skip post-commit hook
我的仓库中有一个 git 提交后挂钩。 我有时想跳过运行这个钩子。
要跳过 pre-commit 钩子,我知道我可以在像这样提交时使用 --no-verify 标志
git commit -m "message" --no-verify
但这并没有跳过提交后挂钩。
是否可以跳过提交后挂钩? 如果有怎么办?
从文档:
-n --no-verify 此选项绕过 pre-commit 和 commit-msg 挂钩。 另见 githooks[5]。
所以这个标志不会跳过 post-commit 钩子。 似乎没有一种简单、干净的方法来跳过这个标志。 对于一次性操作; 您可以禁用钩子并在提交后再次启用它:
chmod -x .git/hooks/post-commit # disable hook
git commit ... # create commit without the post-commit hook
chmod +x .git/hooks/post-commit # re-enable hook
有可能的。 这是我将为 Linux 和 bash 做的事情:
#!/bin/bash
# parse the command line of the parent process
# (assuming git only invokes the hook directly; are there any other scenarios possible?)
while IFS= read -r -d $'\0' ARG; do
if test "$ARG" == '--no-verify'; then
exit 0
fi
done < /proc/$PPID/cmdline
# or check for the git config key that suppresses the hook
# configs may be supplied directly before the subcommand temporarily (or set permanently in .git/config)
# so that `git -c custom.ignorePostCommitHookc=<WHATEVER HERE> commit ...` will suppress the hook
if git config --get custom.ignorePostCommitHook > /dev/null; then
exit 0
fi
# otherwise, still run the hook
echo '+---------+'
echo '| H O O K |'
echo '+---------+'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.