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

Why git-revert doesn't invoke the pre-commit and the commit-msg hooks?

From
Gustavo Chaves <gustavo@gnustavo.com>
Date
Feb 13, 2018, 22:27 UTC
Message-ID
<CAPx58qqv84+i0JbdsVzFqWB=bRDecWHxss8frD4=nWOsFj-NPg@mail.gmail.com>
Using strace I noticed that git-revert invokes only two hooks:
- prepare-commit-msg
- post-commit
But git-commit invoke these four:
- pre-commit
- prepare-commit-msg
- commit-msg
- post-commit

Since git-revert produces a commit, why doesn't it invoke the same hooks as git-commit?

I couldn't find any discussing about this in the list or elsewhere. So I'm asking here.

I ended up researching this when I was implementing a hook to detect and deny commits which revert merge-commits, since they are troublesome (https://www.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.html). I tried to implement it as a commit-msg hook to search for the string "This reverts commit SHA-1" in the commit message. But git-revert doesn't invoke the commit-msg hook.

So, for now I implemented my check as a pre-receive hook. But I find it useful to have all pre-receive checks implemented also as a pre-commit or a commit-msg hook so that I can detect problems at commit time instead of only at push time.

-- 
Gustavo Chaves
Next: Gustavo Chaves
Message 1 of 5 in “Why git-revert doesn't invoke the pre-commit and the commit-msg hooks?”
  1. Gustavo ChavesFeb 13, 2018
  2. Gustavo ChavesFeb 19, 2018
  3. Phillip WoodFeb 20, 2018
  4. Junio C HamanoFeb 20, 2018
  5. Gustavo ChavesFeb 21, 2018

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.