跳过Git提交钩子
I'm looking at a git hook which looks for print statements in Python code. 我正在寻找一个git钩子,它在Python代码中
本文翻译自:Skip Git commit hooks
I'm looking at a git hook which looks for print statements in Python code. 我正在寻找一个git钩子,它在Python代码中查找print语句。 If a print statement is found, it prevents the git commit. 如果找到print语句,则会阻止git commit。
I want to override this hook and I was told that there is a command to do so. 我想覆盖这个钩子,我被告知有一个命令可以这样做。 I haven't been able to find it. 我找不到它。 Any thoughts? 有什么想法吗?
#1楼
参考:https://stackoom.com/question/UL48/跳过Git提交钩子
#2楼
Maybe (from git commit
man page ): 也许(从git commit
手册页 ):
git commit --no-verify
-n
--no-verify
This option bypasses the pre-commit and commit-msg hooks. 此选项绕过pre-commit和commit-msg挂钩。 See also githooks(5) . 另见githooks(5) 。
As commented by Blaise , -n
can have a different role for certain commands. 正如Blaise 评论的那样, -n
可以对某些命令有不同的作用。
For instance, git push -n
is actually a dry-run push. 例如, git push -n
实际上是一个干运行推送。
Only git push --no-verify
would skip the hook. 只有git push --no-verify
会跳过钩子。
Note: Git 2.14.x/2.15 improves the --no-verify behavior: 注意:Git 2.14.x / 2.15改进了--no-verify行为:
See commit 680ee55 (14 Aug 2017) by Kevin Willford (``) . 见Kevin Willford的 承诺680ee55 (2017年8月14日) (``) 。
(Merged by Junio C Hamano -- gitster
-- in commit c3e034f , 23 Aug 2017) (由Junio C gitster
合并- gitster
- in commit c3e034f ,2017年8月23日)
commit
: skip discarding the index if there is nopre-commit
hookcommit
:如果没有pre-commit
挂钩,则跳过丢弃索引"
git commit
" used to discard the index and re-read from the filesystem just in case thepre-commit
hook has updated it in the middle; “git commit
”用于丢弃索引并从文件系统重新读取,以防pre-commit
钩子在中间更新它; this has been optimized out when we know we do not run thepre-commit
hook. 当我们知道我们没有运行pre-commit
钩子时,这已被优化。
Davi Lima points out in the comments the git cherry-pick
does not support --no-verify. DAVI利马指出, 在意见的git cherry-pick
不支持--no-验证。
So if a cherry-pick triggers a pre-commit hook, you might, as in this blog post , have to comment/disable somehow that hook in order for your git cherry-pick to proceed. 因此,如果一个樱桃挑选触发预提交钩子,你可能会像在这篇博客文章中那样以某种方式评论/禁用该钩子,以便你的git cherry-pick继续进行。
The same process would be necessary in case of a git rebase --continue
, after a merge conflict resolution. 在git rebase --continue
情况下,同样的过程是必要的 - 在合并冲突解决后继续。
#3楼
From man githooks
: 来自man githooks
:
pre-commit 预提交
This hook is invoked by git commit, and can be bypassed with --no-verify option. 这个钩子由git commit调用,可以用--no-verify选项绕过。 It takes no parameter, and is invoked before obtaining the proposed commit log message and making a commit. 它不需要参数,并在获取建议的提交日志消息和进行提交之前被调用。 Exiting with non-zero status from this script causes the git commit to abort. 从此脚本退出非零状态会导致git commit中止。
更多推荐
所有评论(0)