Why is a Git post-commit hook on non-interactive rebase not run?
Asked Answered
G

2

6

Given an arbitrary, executable Git post-commit hook it is not run during a non-interactive rebase, neither with rebase --force-rebase nor with rebase --no-ff which is a synonym for the former in non-interactive mode according to the GIT-REBASE(1) Manpage.

But by doing an interactive rebase with rebase --interactive --no-ff the very same Git hook is run on post-commit.

Can someone explain the rationale behind this behavior.

Gundry answered 31/3, 2015 at 14:59 Comment(0)
G
3

But by doing an interactive rebase with rebase --interactive --no-ff, the very same Git hook is run on post-commit.

Actually, the post-commit hook is not run on an interactive rebase since Git 2.17+ (Q4 2017)

It is only run again (on git rebase -i) with Git 2.25+ (Q1 2020): "rebase -i" ceased to run the post-commit hook by mistake in an earlier update, which has been corrected.

See commit 4627bc7, commit 49697cb, commit 12bb7a5, commit 6a619ca, commit b2dbacb, commit 88a92b6 (15 Oct 2019) by Phillip Wood (phillipwood).
(Merged by Junio C Hamano -- gitster -- in commit 5c8c0a0, 10 Nov 2019)

sequencer: run post-commit hook

Signed-off-by: Phillip Wood

Prior to commit 356ee4659b ("sequencer: try to commit without forking 'git commit'", 2017-11-24, Git v2.17.0-rc0 -- merge listed in batch #2) the sequencer would always run the post-commit hook after each pick or revert as it forked git commit to create the commit.

The conversion to committing without forking git commit omitted to call the post-commit hook after creating the commit.

Gigantean answered 13/11, 2019 at 17:12 Comment(3)
Is there any alternative to bypass rebase -i running the post-commit hooks?Kellam
@Kellam If you mean "avoid running the post-commit hook after an interactive rebase", then no, with recent Git version, that does not seem possible (looking at the source code github.com/git/git/commit/…)Gigantean
Thanks for the answerKellam
Q
0

From https://git-scm.com/docs/git-rebase

--no-ff With --interactive, cherry-pick all rebased commits instead of fast-forwarding over the unchanged ones. This ensures that the entire history of the rebased branch is composed of new commits.

Without --interactive, this is a synonym for --force-rebase.

You may find this helpful after reverting a topic branch merge, as this option recreates the topic branch with fresh commits so it can be remerged successfully without needing to "revert the reversion" (see the revert-a-faulty-merge How-To for details).

Cherry pick creates new commits, and git post-commit hook runs after new commit is created, right?

From: https://git-scm.com/docs/git-cherry-pick

DESCRIPTION Given one or more existing commits, apply the change each one introduces, recording a new commit for each. This requires your working tree to be clean (no modifications from the HEAD commit).

Is that clear?

Quell answered 16/10, 2015 at 8:12 Comment(2)
So, how does that affect the commit hook? Please explain.Jotting
I think this explains why the hook does trigger, but you didn't explain why the hook might not trigger.Jotting

© 2022 - 2024 — McMap. All rights reserved.