get commit message in git hook

前端 未结 4 1061
滥情空心
滥情空心 2020-12-03 06:49

I would like to check commit message before git commit. I use pre-commit hook to do that, but couldn\'t find the way to get commit message in .git/pre-commit script. How cou

4条回答
  •  借酒劲吻你
    2020-12-03 07:50

    In the pre-commit hook, the commit message usually hasn't been created yet 1. You probably want to use one of the prepare-commit-msg or commit-msg hooks instead. There's a nice section in Pro Git on the order in which these hooks are run, and what you typically might do with them.

    1. The exception is that the committer might have supplied a commit message with -m, but the message still isn't accessible to the pre-commit hook, whereas it is to prepare-commit-msg or commit-msg

提交回复
热议问题