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.

Tim Friske
  • 2,012
  • 1
  • 18
  • 28

2 Answers2

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Is there any alternative to bypass `rebase -i` running the `post-commit` hooks? – mochadwi Jul 21 '20 at 13:45
  • @mochadwi 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 https://github.com/git/git/commit/5c8c0a0d78b0e0ee50ba13823f0cfbee05334461) – VonC Jul 21 '20 at 18:11
  • Thanks for the answer – mochadwi Jul 21 '20 at 19:58
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?

grimsock
  • 774
  • 5
  • 18
  • So, how does that affect the commit hook? Please explain. – ams Oct 16 '15 at 08:18
  • I think this explains why the hook *does* trigger, but you didn't explain why the hook might *not* trigger. – ams Oct 19 '15 at 09:05