From: "Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com>
To: git@vger.kernel.org
Subject: Re: Interaction between pre-commit hook and git commit <pathspec>
Date: Tue, 03 Nov 2026 21:13:37 +0100 [thread overview]
Message-ID: <de4f4f35-500f-4d82-acfd-ca601444f2d2@app.fastmail.com> (raw)
In-Reply-To: <CY8PR17MB6236D16AD8CD80720FF1342DAE692@CY8PR17MB6236.namprd17.prod.outlook.com>
On Tue, Nov 3, 2026, at 20:58, Kevin Lyles wrote:
> Hello, folks,
>
> The documentation for the pathspec option of the commit command claims:
> "The contents of these files are also staged for the next commit on top
> of what have been staged before."
> However, that appears to only be true if the pre-commit hook doesn't
> modify the index contents.
>
> Here's an example pre-commit script:
> #!/bin/sh
>
> git diff --staged --name-only | while read -r file
> do
> {
> git cat-file blob :"$file"
> echo '# Extra text'
> } |
> {
> echo -n "100644 blob "
> echo -n $(git hash-object -w -t blob --path "$file" --stdin)
> echo -e "\t$file"
> } |
> git update-index --index-info
> echo '# Extra text' >> "$file"
> done
>
> This always appends "# Extra text" to the end of any staged files, in
> both the index and the worktree. It serves to illustrate the issue,
> without getting into the weeds of what my pre-commit hook is doing.
> Suffice to say that my hook is (sometimes) modifying files in both the
> index (to make sure the updated contents are committed) and the
> worktree (to reduce spurious diffs when file contents are changed).
>[snip]
Reading githooks documentation for
pre-commit. To me it reads like the use case
is validation/checking, not any mutation.
This doesn't sound like a reasonable use case.
next prev parent reply other threads:[~2026-11-03 20:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 19:58 Interaction between pre-commit hook and git commit <pathspec> Kevin Lyles
2026-11-03 20:13 ` Kristoffer Haugsbakk [this message]
2026-11-03 20:38 ` Junio C Hamano
2026-11-03 20:43 ` Chris Torek
2026-11-04 16:34 ` Kevin Lyles
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=de4f4f35-500f-4d82-acfd-ca601444f2d2@app.fastmail.com \
--to=kristofferhaugsbakk@fastmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox