git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: hook to get info on commit, and include that in a file that is part of the commit

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Feb 5, 2019, 01:55 UTC
Message-ID
<20190205015506.GB527887@genre.crustytoothpaste.net>
In-Reply-To
<CACwCsY5xU0pUaPZDJMqWNB0dz7DjTx3_b2Lvrft0NjA6cnPvcg@mail.gmail.com>
On Mon, Feb 04, 2019 at 08:36:10PM -0500, Larry Martell wrote:
Show 6 quoted lines
> Is there any way using a git hook to get info on the commit (id,
> message), put that in a file, and include that file in the commit?
> 
> If I try that in a pre-commit hook I do not get the info on the
> current commit. I tried it in pre-receive but it does not seem to get
> executed at all.
You cannot include a file in the commit with that commit's ID.

The object ID of a commit is based on the data it contains, which is in turn based on the data in its top-level tree, which is in turn based on the data in all of its trees and blobs. If you add or change a file in a commit (or the message of that commit), you necessarily result in that commit having a different object ID. This is by design and is valuable for checking the integrity of the history.

Furthermore, the hooks for a commit are designed for checking and notification, not for editing the commit, with the exception of the commit message hooks, which are designed only for editing the commit message, not the contents.

The pre-receive hook runs on the server side, so if you aren't running it there, then it won't get called at all.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: Larry MartellNext: Larry Martell
Message 2 of 7 in “hook to get info on commit, and include that in a file that is part of the commit”
  1. Larry MartellFeb 5, 2019
  2. brian m. carlsonFeb 5, 2019
  3. Larry MartellFeb 5, 2019
  4. brian m. carlsonFeb 5, 2019
  5. Larry MartellFeb 5, 2019
  6. brian m. carlsonFeb 5, 2019
  7. Larry MartellFeb 5, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.