gpt4 book ai didi

git - 为什么 git-revert 不调用 pre-commit 和 commit-msg Hook ?

转载 作者:太空狗 更新时间:2023-10-29 13:42:24 24 4
gpt4 key购买 nike

使用 strace 我注意到 git-revert 只调用两个钩子(Hook):

  • 准备提交消息
  • 提交后

但是 git-commit 调用这四个:

  • 预提交
  • 准备提交消息
  • 提交消息
  • 提交后

既然 git-revert 产生了一个提交,为什么它不调用相同的钩子(Hook)作为 git-commit?

我在 Git 邮件列表中询问过这个问题,但没有得到任何回应。所以我在这里问。

当我实现一个钩子(Hook)来检测时,我最终研究了这个并拒绝恢复 merge 提交的提交,因为它们是 troublesome .

我试图将它实现为一个 commit-msg 钩子(Hook)来搜索字符串提交消息中的“这会还原提交 SHA-1”。但是 git-revert不调用 commit-msg Hook 。

所以,现在我将检查实现为预接收 Hook 。但我发现将所有预接收检查也作为预提交或提交消息 Hook ,以便我可以检测到问题提交时间而不是仅在推送时间。

最佳答案

The sequencer code actually runs git commit to produce the commit .但是这段代码(见上面的链接)包含片段:

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

这意味着它默认运行 git commit -n-n 标志:

bypasses the pre-commit and commit-msg hooks

the git commit documentation. 中所述设置 VERIFY_MSG 的东西是交互式 rebase “编辑”或“改写”等,但不是 git cherry-pick

请注意,一旦音序器完成,它将调用您的重写后 Hook (如果您有的话),因此您应该将检查放在那里。正如您所注意到的,您可以专门编辑提交消息,如果您这样做,您的提交消息 Hook 似乎应该被使用,但事实并非如此。

关于git - 为什么 git-revert 不调用 pre-commit 和 commit-msg Hook ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48852925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com