threads / discuss / 64089

Config options -c in rebase --continue not passed to prepare-commit-msg hook

Subject: Config options -c in rebase --continue not passed to prepare-commit-msg hook

## tl;dr

2 messages between Sep 4, 2025 and Sep 5, 2025.

replies: 1people: 2as markdown or json

Devste Devste· Sep 4, 2025, 12:46 UTC · lore

For some reason neither environment variables nor -c is passed to the prepare-commit-msg hook when rebasing. Other parameters (e.g. -C /path/to/repo) are passed correctly/it's running the command in the correct repo

Reproduction:
1) Create a prepare-commit-msg hook with content
echo "prepare-commit-msg hook"
echo "$FOO"
git config --get hooks.foobar
exit 1
2) rebase a branch with conflicts. After resolving a conflict run:
FOO=bar git -c hooks.foobar=hello rebase --continue

The hook is executed but neither $FOO nor the config are set (both echo an empty line) Output: prepare-commit-msg hook

Expected output: prepare-commit-msg hook bar hello

Git 2.51.0
Jeff King· Sep 5, 2025, 21:23 UTC · re: Devste Devste · lore

Re: Config options -c in rebase --continue not passed to prepare-commit-msg hook

On Thu, Sep 04, 2025 at 02:46:13PM +0200, Devste Devste wrote:
> For some reason neither environment variables nor -c is passed to the
> prepare-commit-msg hook when rebasing.
> Other parameters (e.g. -C /path/to/repo) are passed correctly/it's
> running the command in the correct repo

If the environment is being cleared, then that would explain "-c" as well, since it passes through the environment. However, I can't reproduce the problem here.

This is my full recipe:

-- >8 -- git init git checkout main echo base >file && git add file && git commit -m base echo main >>file && git commit -am main git checkout -b side HEAD^ echo side >>file && git commit -am side

cat >.git/hooks/prepare-commit-msg <<\EOF #!/bin/sh echo "in prepare-commit-msg hook" echo "FOO: $FOO" echo "config: $(git config --get hooks.foobar)" exit 1 EOF chmod +x .git/hooks/prepare-commit-msg

git rebase main echo resolved >file git add file FOO=bar git -c hooks.foobar=hello rebase --continue -- >8 --

The final command produces:
  in prepare-commit-msg hook
  FOO: bar
  config: hello
  error: could not commit staged changes.

which is what I'd expect. Do you get the same thing? If not, then I wonder what could be different between our environments. If so, then I wonder what is different from your earlier testing. :)

-Peff

← back to recent threads