Git post-rebase hook

后端 未结 2 855
余生分开走
余生分开走 2021-02-13 06:33

Is there such thing as post-rebase hook? My goal is that I want a script to execute after git pull --rebase command is used.

相关标签:
2条回答
  • 2021-02-13 06:59

    A post-checkout hook could work too, but only with with Git 2.21 (Q1 2019): "git rebase" internally runs "checkout" to switch between branches, and the command used to call the post-checkout hook, but the reimplementation (from shell script to C) stopped doing so, which is getting fixed.

    See commit 8581df6, commit 10499a9 (29 Dec 2018) by Orgad Shaneh (orgads).
    (Merged by Junio C Hamano -- gitster -- in commit d94ade7, 29 Jan 2019)

    rebase: run post-checkout hook on checkout

    The scripted version of rebase used to run this hook on the initial checkout.
    The transition to built-in introduced a regression.


    With Git 2.27 (Q2 2020), "git rebase" happens to call some hooks meant for "checkout" and "commit" by this was not a designed behaviour than historical accident.

    This has been documented.

    See commit f7139e7 (05 Apr 2020) by Elijah Newren (newren).
    (Merged by Junio C Hamano -- gitster -- in commit 1779d18, 28 Apr 2020)

    git-rebase.txt: add another hook to the hooks section, and explain more

    Signed-off-by: Elijah Newren

    For more discussion about these hooks, their history relative to rebase, and logical consistency between different types of operations, see this git mailing-list thread and the links to some threads referenced therein.

    The git rebase hook section now includes:

    Hooks

    The apply backend has not traditionally called the post-commit hook, while the merge backend has.

    Both have called the post-checkout hook, though the merge backend has squelched its output.

    Further, both backends only call the post-checkout hook with the starting point commit of the rebase, not the intermediate commits nor the final commit.
    In each case, the calling of these hooks was by accident of implementation rather than by design (both backends were originally implemented as shell scripts and happened to invoke other commands like 'git checkout' or 'git commit' that would call the hooks).

    Both backends should have the same behavior, though it is not entirely clear which, if any, is correct.
    We will likely make rebase stop calling either of these hooks in the future.

    0 讨论(0)
  • 2021-02-13 07:07

    Seems like post-rewrite hook does the job.

    0 讨论(0)
提交回复
热议问题