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

Re: Git not commiting anything if file created and "git add"ed in pre-commit hook is the only file in the staging area

From
PHPeter Hunkeler <phunsoft@gmx.net>
Date
Oct 28, 2021, 12:08 UTC
Message-ID
<dd79e443-3bb9-8b83-746b-7db7c4997ee3@gmx.net>
In-Reply-To
<YXnNvyi62j5gcxQV@camp.crustytoothpaste.net>
Am 28.10.2021 um 00:07 schrieb brian m. carlson:
> I should point out here that it isn't intended for pre-commit hooks to
> be used this way; they're intended to verify that the commit meets some
> standards, not to modify it, although it is of course possible to do.
>
I can accept that comment. However:
- wouldn't you agree that git should work consistently? It does not in
this case. If there is anything to be commited in the index, then the
"git add" from within the pre-commit hook *is* respected in this commit.
If there is *nothing* to be commited, except from what was added by the
pre-commit exit, then it is ignored *for this commit*, but it is added
and will be commited next time. This is inconsistent behaviour.
- if the decision will be *not* to allow adding from within a pre-commit
hook, then the "git add" should be rejected. And the documentation
should say so.

I'll have to understand what all the comments from you and others mean (still a git newbee).

> In general, you want to avoid adding automatically generated files to
> your repository.  That tends to bloat the repository needlessly and is a
> great way to lead to frequent, hard-to-resolve merge conflicts.
>

I'm trying to use git to keep track of changes to my website, which uses some framework. The problem is: Some changes modify filesystem entities, only, while other changes modify the content of some mysql tables. So I need to pack an unload of those tables into the commit. I can do this manually (and forget every now and then :-), or I thought the pre-commit hook would be a good place to automate this. And, yes, it may well crete merge conflicts.

I understand the pre-commit hook is a local thing, and I have to make sure the same is active in all repositories. Definitely not something to use in a widely shared project.

Thanks a lot Peter

Previous: Junio C HamanoNext: Peter Hunkeler
Message 5 of 9 in “Git not commiting anything if file created and "git add"ed in pre-commit hook is the only file in the staging area”
  1. Peter HunkelerOct 27, 2021
  2. brian m. carlsonOct 27, 2021
  3. Jeff KingOct 27, 2021
  4. Junio C HamanoOct 28, 2021
  5. Peter HunkelerOct 28, 2021
  6. Peter HunkelerOct 30, 2021
  7. Johannes SixtOct 30, 2021
  8. Junio C HamanoOct 30, 2021
  9. Peter HunkelerNov 2, 2021

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.