跳过 Git 提交挂钩
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7230820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Skip Git commit hooks
提问by Ben
I'm looking at a git hook which looks for print statements in Python code. If a print statement is found, it prevents the git commit.
我正在查看一个 git 钩子,它在 Python 代码中查找打印语句。如果找到打印语句,它会阻止 git 提交。
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?
我想覆盖这个钩子,有人告诉我有一个命令可以这样做。我一直无法找到它。有什么想法吗?
回答by VonC
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. See also githooks(5).
此选项绕过 pre-commit 和 commit-msg 挂钩。另请参阅githooks(5)。
As commentedby Blaise, -n
can have a different role for certain commands.
For instance, git push -n
is actually a dry-run push.
Only git push --no-verify
would skip the hook.
正如Blaise评论的那样,对于某些命令可以有不同的作用。
例如,实际上是空运行推。
只会跳过钩子。-n
git push -n
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 (``).
(Merged by Junio C Hamano -- gitster
--in commit c3e034f, 23 Aug 2017)
请参阅Kevin Willford (``) 的提交 680ee55(2017 年 8 月 14 日)。
(由Junio C gitster
Hamano合并-- --在提交 c3e034f 中,2017 年 8 月 23 日)
commit
: skip discarding the index if there is nopre-commit
hook"
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; this has been optimized out when we know we do not run thepre-commit
hook.
commit
: 如果没有pre-commit
钩子,跳过丢弃索引"
git commit
" 用于丢弃索引并从文件系统重新读取,以防万一pre-commit
钩子在中间更新了它;当我们知道我们不运行pre-commit
钩子时,这已经被优化了。
Davi Limapoints out in the commentsthe git cherry-pick
does notsupport --no-verify.
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.
The same process would be necessary in case of a git rebase --continue
, after a merge conflict resolution.
DAVI利马指出,在意见中git cherry-pick
并没有支持--no-验证。
因此,如果cherry-pick 触发了一个预提交钩子,您可能会像在这篇博文中一样,必须以某种方式评论/禁用该钩子,以便您的 git cherry-pick 继续进行。在合并冲突解决之后
,如果出现git rebase --continue
, 则需要相同的过程。
回答by Chris Eberle
From man githooks
:
来自man githooks
:
pre-commit
This hook is invoked by git commit, and can be bypassed with --no-verify option. 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.
pre-commit
这个钩子由 git commit 调用,可以通过 --no-verify 选项绕过。它不接受任何参数,并且在获取建议的提交日志消息并进行提交之前被调用。从此脚本以非零状态退出会导致 git commit 中止。
回答by Moumit
For those very beginners
who has spend few hours for this commit (with comment
and no verify
) with no further issue
对于那些very beginners
花了几个小时进行此提交(使用comment
和no verify
)而没有进一步问题的人
git commit -m "Some comments" --no-verify