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

Fwd: git commit --verbose shows incorrect diff when pre-commit hook is used to modify files

From
SLSergey Lukashev <lukashev.s@ya.ru>
Date
Feb 11, 2019, 23:20 UTC
Message-ID
<3762191549927209@iva8-3af116a85b74.qloud-c.yandex.net>
In-Reply-To
<3307861549925664@iva7-ddadfcd6463f.qloud-c.yandex.net>

-------- Пересылаемое сообщение -------- 12.02.2019, 01:54, "Sergey Lukashev" <lukashev.s@ya.ru>:

Indeed. Sorry, this was how I thought it works.
So the hook runs even if the commit is cancelled. A bit odd.
Then let's have someone else from git list to answer your question.
12.02.2019, 01:11, "Fernando Chorney" <djsbx@djsbx.com>:
Show 32 quoted lines
>  Hmm, so I currently have it set to run vim as my commit editor, and
>  enter the message in there most of the time. I can definitely see
>  output from the hook into the shell before my vim editor loads up that
>  shows me the diff and lets me add in the commit message. This leads me
>  to believe that the pre-commit hook is being run before the editor
>  (with the diff) pops up.
>
>  On Mon, Feb 11, 2019 at 4:04 PM Sergey Lukashev <lukashev.s@ya.ru> wrote:
>>   At the time you see the diff the committing of changes has not yet been initiated. It's only after you type in the message that the ACTUAL committing starts and the hook runs.
>>
>>   You can print the diff of what your hook has changed by running "git diff" in it before adding changes.
>>
>>   12.02.2019, 00:28, "Fernando Chorney" <djsbx@djsbx.com>:
>>   > Hi,
>>   >
>>   > I am trying to use a pre-commit hook to modify files before they are
>>   > to be committed. The problem I am running into is that if I use "git
>>   > commit --verbose", which I often do so that I can see the diff, the
>>   > diff it displays in the editor is the diff before the pre-commit hook
>>   > was run rather than what the diff would be after the pre-commit was
>>   > run.
>>   >
>>   > I would like to note, that the pre-commit hook is definitely running,
>>   > but when git grabs the diff seems to be in the wrong place.
>>   >
>>   > I have set up a simple example on my github to show the problem.
>>   > https://github.com/fchorney/pre-commit-example
>>   >
>>   > Is this intended behaviour, or perhaps an issue?
>>   >
>>   > Thanks,
>>   > Fernando Chorney
-------- Конец пересылаемого сообщения --------
Message 1 of 1 in “Fwd: git commit --verbose shows incorrect diff when pre-commit hook is used to modify files”
  1. Sergey LukashevFeb 11, 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.