简体   繁体   English

我可以像在git中那样跳过预提交的钩子吗?

[英]Can I skip mercurial pre-commit hooks like in git?

I want to do something like git commit --no-verify but with mercurial. 我想做一些类似git commit --no-verify事情,但要谨慎一些。 Are any ways to do it? 有什么办法吗?

As noted in the hg help config documentation : hg help config文档中所述

... Multiple hooks can be run for the same action by appending a suffix to the action. ...通过为操作添加后缀,可以为同一操作运行多个钩子。 Overriding a site-wide hook can be done by changing its value or setting it to an empty string. 可以通过更改其值或将其设置为空字符串来覆盖整个站点范围的挂钩。 Hooks can be prioritized by adding a prefix of "priority." 可以通过添加前缀“ priority”来对挂钩进行优先级排序。 to the hook name on a new line and setting the priority. 到新行上的钩子名称并设置优先级。 The default priority is 0. 默认优先级为0。

(emphasis mine). (强调我的)。 While this refers to "system-wide hooks", it works for in-repository hooks as well: 虽然这是指“系统范围内的钩子”,但它也适用于存储库中的钩子:

$ sed -n '/hooks/,+1p' .hg/hgrc
[hooks]
pre-commit = ./foo.sh
$ cat foo.sh
#! /bin/sh
echo foo
exit 1
$ hg commit
foo
abort: pre-commit hook exited with status 1

Obviously my pre-commit hook is working. 显然,我的预提交挂钩正在工作。 Now to defeat it: 现在要击败它:

$ hg --config hooks.pre-commit= commit
nothing changed

(there was nothing to commit; overriding the pre-commit hook worked). (没有要提交的内容;覆盖预提交的钩子是可行的)。

You will, of course, need to know which specific hook(s) you want to override, since there may be more than one pre-commit hook. 当然,您可能需要知道要覆盖哪个特定的钩子,因为可能有多个预提交的钩子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM