相关疑难解决方法(0)

如何捕获git提交消息并运行操作

我是git的新手,我希望能够在推送到origin/master之后捕获提交消息,并根据字符串包含的内容运行bash脚本(在服务器上).

例如,如果我的git commit消息说: [email] my commit message

如果提交消息包含[email]然后执行指定的操作,否则不要这样做.

这是我想在post-receive钩子中使用的示例bash脚本:

#!/bin/bash

MESSAGE= #commit message variable?

if [[ "$MESSAGE" == *[email]* ]]; then
        echo "do action here"
else
        echo "do nothing"
fi
Run Code Online (Sandbox Code Playgroud)

基本上我需要知道的是提交消息的变量名是什么,在上面的bash脚本中使用?另外,我不确定这是否是正确的钩子.

git bash githooks

9
推荐指数
1
解决办法
8376
查看次数

标签 统计

bash ×1

git ×1

githooks ×1