本文介绍了为什么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 samehooks 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 detectand deny commits which revert merge-commits, since they aretroublesome.

我试图将其实现为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-revertdoesn't invoke the commit-msg hook.

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

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

推荐答案

定序器代码实际上运行git commit来生成提交.但是此代码(请参见上面的链接)包含片段:

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:

,如 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.

如您所注意到的,您可以专门编辑提交消息,如果这样做,似乎应该使用您的提交消息钩子应该,但实际上并没有.

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钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 06:10