为什么git-revert不调用pre-commit和commit-msg钩子? [英] Why git-revert doesn't invoke the pre-commit and the commit-msg hooks?

查看:105
本文介绍了为什么git-revert不调用pre-commit和commit-msg钩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用strace我注意到git-revert仅调用两个钩子:

Using strace I noticed that git-revert invokes only two hooks:

  • prepare-commit-msg
  • 提交后

但是git-commit调用这四个:

But git-commit invoke these four:

  • 预提交
  • prepare-commit-msg
  • commit-msg
  • 提交后

由于git-revert产生了一个提交,为什么它不调用相同的提交 钩为git-commit吗?

Since git-revert produces a commit, why doesn't it invoke the same hooks as git-commit?

我在Git邮件列表中询问了此问题,但没有得到回应.所以我要问这里.

I asked this on the Git mailing list but got no response. So I'm asking here.

当我实现一个钩子来检测时,我最终进行了研究 并拒绝恢复合并提交的提交,因为它们是 麻烦.

I ended up researching this when I was implementing a hook to detect and deny commits which revert merge-commits, since they are troublesome.

我试图将其实现为commit-msg挂钩,以搜索字符串 提交消息中的这将还原提交SHA-1".但是git-revert 不会调用commit-msg挂钩.

I tried to implement it as a commit-msg hook to search for the string "This reverts commit SHA-1" in the commit message. But git-revert doesn't invoke the commit-msg hook.

因此,现在我将支票实现为预接收钩子.但是我发现 将所有预接收检查也作为 pre-commit或commit-msg挂钩,以便我可以在以下位置检测问题 提交时间,而不是仅在推送时间.

So, for now I implemented my check as a pre-receive hook. But I find it useful to have all pre-receive checks implemented also as a pre-commit or a commit-msg hook so that I can detect problems at commit time instead of only at push time.

推荐答案

The sequencer code actually runs git commit to produce the commit. But this code (see link above) contains the fragment:

    if (!(flags & VERIFY_MSG))
            argv_array_push(&cmd.args, "-n");

表示默认情况下运行git commit -n. -n标志:

which means it runs git commit -n by default. The -n flag:

绕过pre-commit和commit-msg钩子

bypasses the pre-commit and commit-msg hooks

,如 git commit文档中所述. 设置VERIFY_MSG的内容是交互式"reedit"或"reword"之类的内容,而不是git cherry-pick.

as noted in the git commit documentation. The things that set VERIFY_MSG are interactive rebase "edit" or "reword" and the like, but not git cherry-pick.

请注意,一旦音序器完成,它将调用您的重写后钩子(如果有的话),因此您应该将支票放在那儿.如您所注意到的,您可以专门编辑提交消息,如果这样做,似乎应该使用您的提交消息钩子应该,但实际上并没有.

Note that once the sequencer is done, it will invoke your post-rewrite hook (if you have one), so you should put your check there instead. As you note, you can specifically edit the commit message, and if you do so, it seems like your commit messge hook ought to be used, but it isn't.

这篇关于为什么git-revert不调用pre-commit和commit-msg钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆