在git钩子中获取提交消息

问题描述:

我想在git commit之前检查提交消息。
我使用pre-commit钩子来做到这一点,但是找不到在.git / pre-commit脚本中获取提交信息的方式。
我怎么能得到它?

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 could I get it?

在预提交钩子中,提交消息尚未创建然而。您可能希望使用 prepare-commit-msg commit-msg 钩子之一。订单中有 Pro Git中的精美版块哪些钩子运行,以及你通常可以用它们做什么。

In the pre-commit hook, the commit message hasn't been created yet. 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.