写一个post commit hook来推送到我的暂存站点,但不要认为它是出于某种原因而运行

时间:2013-06-27 19:29:58

标签: git

我的帖子提交挂钩有以下设置:

<。>在.git / hooks / push-to-staging

#!/bin/sh

while read oldrev newrev refname
do
  branch=$(git rev-parse --symbolic --abbrev-ref $refname)
  git push -f myapp $branch:master && heroku run rake db:migrate -a my-app && heroku restart -a my-app
done

我确保chmod + x push-to-staging。

然而,当我推到我的任何一个分支时,推动显然很好......但是那就是它。我没有看到推送到我的登台服务器。

其次,我想知道是否有办法让这个帖子提交钩子我的回购的一部分(或者不是钩子应该如何工作?)。我只是想让我的团队中的每个人基本上都有这个设置。

1 个答案:

答案 0 :(得分:0)

Git中没有这样的钩子:push-to-staging。您可以在存储库的hooks目录中看到可用的挂钩,例如在我的系统中:

applypatch-msg
commit-msg
post-commit
post-receive
post-update
pre-applypatch
pre-commit
prepare-commit-msg
pre-rebase
update

在您的情况下,您正在寻找post-commit挂钩。将脚本重命名为post-commit,或者从post-commit创建指向您脚本的符号链接。

您不能将钩子作为存储库的一部分,也就是说,您不能自动启用钩子并通过分支操作传播。如果可能的话,克隆存储库时将面临巨大的安全风险。你可以做的是让启用钩子脚本变得容易,你可以在其他答案中看到它的例子:

Putting git hooks into repository

Tracking changes to hooks in .git/hooks