首页 > 解决方案 > 创建一个 git post-push 钩子

问题描述

我正在尝试为 git 创建一个推送后挂钩。目标只是在将代码推送到 Github 后运行 shell 命令来启动 gitrob。我发现了这个:https ://stackoverflow.com/a/3812238/9709330 但我是一个菜鸟 Linux 用户,当我将我的 post-push 挂钩保存为 /usr/local/bin 中的“git-push-wh”时(它在我的 $PATH 中),它没有改变任何东西,当我运行 git push-w 时它无法识别。

有什么帮助吗?或任何其他方式来做到这一点?谢谢 :)

标签: linuxgitgithubpathgithooks

解决方案


一种想法是将函数添加到您的~/.bashrc~/.zshrc您的 shell 可以访问该函数的方式中,您可以简单地通过函数名称调用 shell 中的函数。在将函数添加到这些文件中的任何一个之后,您还需要告诉您的 shell 进行更新,source ~/.bashrc这样就可以了。

我的例子~/.bashrc

function test() {
   echo "yo"
}

然后我source ~/.bashrc 在我的 shell 中运行 and now:

bash-3.2$ test
yo

我希望这有帮助!


推荐阅读