推送后 Git 后接收挂钩未运行 [英] Git post-receive hook not running following push

查看:22
本文介绍了推送后 Git 后接收挂钩未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Amazon EC2 实例(运行 Ubuntu 12.04)上托管了一个网站.我希望能够使用 git 将更改推送到服务器,然后使用 post-receive 挂钩在工作目录中签出.因此,在 hooks 目录中的服务器上,我有一个名为 post-receive 的文件,其中包含:

I have a website hosted on an Amazon EC2 instance (running Ubuntu 12.04). I want to be able to be able to push changes to the server using git and then use a post-receive hook to checkout in the working directory. So on the server in the hooks directory I have a file named post-receive containing:

#!/bin/sh
GIT_WORK_TREE=/home/ubuntu/beta git checkout -f

该文件具有权限:-rwxrwxr-x(即它是可执行的).

The file has the permissions: -rwxrwxr-x (i.e. it is executable).

在我的本地机器上,当我推送到服务器上的git repo时,推送成功并且git repo被更新.但是,不运行 post-receive 挂钩.如果我手动运行钩子,它运行良好并更新工作目录.

On my local machine, when I push to the git repo on the server, the push is successful and the git repo is updated. The post-receive hook is not run, however. If I run the hook manually, it runs fine and updates the working directory.

git push 通过 SSH 执行并使用相同的用户,就像我手动运行钩子一样.

The git push is carried out over SSH and uses the same user as if I were running the hook manually.

为什么钩子不会自动运行的任何想法?

Any ideas why the hook will not run automatically?

谢谢.

推荐答案

我已经设置了一个本地相同的测试(即我从本地文件夹克隆)并且它工作正常.

I've set up an local identical test (ie I cloned from a local folder) and it works fine.

为了查看脚本是否被执行,我添加了一个简单的触摸来查看它是否修改了任何文件

To see if the script is executed at all I've added a simple touch to see if it modifies any files

我的接收后看起来像这样

My post-receive looks like this

#!/bin/sh

touch /Users/raven/git_tests/live/.git/hooks/i_ve_been_run
GIT_WORK_TREE=/Users/raven/git_tests/live git checkout -f

确保您的钩子的名称与 post-receive 完全一致,否则它将无法工作.

Make sure that your hook is named exactly post-receive or it won't work.

这篇关于推送后 Git 后接收挂钩未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆