【问题标题】:Why is a Git post-commit hook on non-interactive rebase not run?为什么非交互式变基上的 Git 提交后挂钩未运行?
【发布时间】:2015-06-04 23:29:27
【问题描述】:

给定一个任意的、可执行的 Git 提交后挂钩,它不会在非交互式 rebase 期间运行,无论是 rebase --force-rebase 还是 rebase --no-ff 根据 GIT 在非交互模式下是前者的同义词-REBASE(1) 手册页。

但是通过使用rebase --interactive --no-ff 进行交互式变基,在提交后运行相同的 Git 挂钩。

有人能解释一下这种行为背后的原因吗?

【问题讨论】:

    标签: git git-rebase post-commit-hook non-interactive


    【解决方案1】:

    来自https://git-scm.com/docs/git-rebase

    --no-ff 使用--interactive,cherry-pick 所有重新定位的提交,而不是快速转发未更改的提交。这确保了整个 重新定位的分支的历史记录由新的提交组成。

    如果没有 --interactive,这是 --force-rebase 的同义词。

    还原主题分支合并后,您可能会发现这很有帮助,因为 此选项使用新提交重新创建主题分支,因此可以 成功重新合并,无需“还原还原”(请参阅 revert-a-faulty-merge How-To 了解详细信息)。

    Cherry pick 创建新的提交,git post-commit 钩子在新的提交创建后运行,对吧?

    发件人:https://git-scm.com/docs/git-cherry-pick

    描述 给定一个或多个现有提交,应用每个引入的更改,为每个提交记录一个新的提交。这要求您的工作树是干净的(不修改 HEAD 提交)。

    清楚吗?

    【讨论】:

    • 那么,这对提交挂钩有何影响?请解释一下。
    • 我认为这解释了为什么钩子确实触发,但你没有解释为什么钩子可能触发。
    【解决方案2】:

    但是通过使用rebase --interactive --no-ff 进行交互式变基,同样的 Git 挂钩会在 post-commit 上运行。

    实际上,自 Git 2.17+(2017 年第四季度)以来,post-commit 钩子没有在交互式变基上运行

    它仅在 Git 2.25+(2020 年第一季度)再次(在 git rebase -i 上)运行:“rebase -i”在较早的更新中错误地停止运行 post-commit 挂钩,已更正。

    参见commit 4627bc7commit 49697cbcommit 12bb7a5commit 6a619cacommit b2dbacbcommit 88a92b6(2019 年 10 月 15 日)Phillip Wood (phillipwood)
    (由Junio C Hamano -- gitster -- 合并commit 5c8c0a0,2019 年 11 月 10 日)

    sequencer:运行post-commit钩子

    签字人:Phillip Wood

    commit 356ee4659b ("sequencer: try to commit without forking 'git commit'", 2017-11-24, Git v2.17.0-rc0 -- merge 列在batch #2) 之前的序列器在每次选择或还原后总是运行 post-commit 钩子,因为它派生了 git commit 以创建提交。

    在不分叉git commit 的情况下转换为在创建提交后调用post-commit 钩子。

    【讨论】:

    • 除了运行rebase -i 钩子,还有什么替代方法可以绕过rebase -i
    • @mochadwi 如果您的意思是“避免在交互式 rebase 之后运行 post-commit 挂钩”,那么不,对于最近的 Git 版本,这似乎是不可能的(查看源代码 github.com/git/git/commit/…
    • 感谢您的回答
    猜你喜欢
    • 2018-09-29
    • 2011-07-02
    • 2014-01-03
    • 2014-08-10
    • 2015-09-10
    • 1970-01-01
    • 2021-09-10
    • 2014-05-13
    • 2021-08-07
    相关资源
    最近更新 更多