Home > Software design >  Is there a way to only skip the commit-msg hook
Is there a way to only skip the commit-msg hook

Time:10-17

I've put a check for the commit message in the commit-msg hook which I want to skip at times. I know there is a git commit --no-verify for the task, but that also skips the pre-commit hook. Is there a way to only skip the commit-msg hook and not the pre-commit?

CodePudding user response:

No, but also yes:

  • Git does not provide a mechanism for this.
  • But Git does not write the commit hooks. You write the commit hooks.

So, write your commit-msg hook so that it checks for some sort of control knob: "if control knob is set one way, check the commit message; if it's set the other way, just accept the commit message".

Your task is now to pick the control knob and make sure it's set the right way at the right time. One obvious possibility is a simple environment variable:

$ SKIP_MESSAGE_CHECK=yes git commit -m "silly message"

(assuming an sh/bash style shell; use env SKIP_MESSAGE_CHECK=yes ... if needed).

  • Related