接收后挂钩失败-有机会看到原因吗? [英] post-receive hook fails - any chance to see why?

查看:45
本文介绍了接收后挂钩失败-有机会看到原因吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现方法,用于将更新发送到我的网站:

I'm implementing this approach to send updates to my website:

创建了要推送到的裸仓库

created bare repository to push to

$ mkdir website.git && cd website.git
$ git init --bare

并添加了以下钩子:

$ mkdir /var/www/example.com
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/example.com git checkout -f
$ chmod +x hooks/post-receive

当我从本地存储库推送到website.git时,更新工作正常.但是没有文件添加到/var/www/example.com中.我如何调查这里可能出什么问题?任何日志或其他内容?

when I push to website.git from local repository, the update works fine. But no files are added into /var/www/example.com. How can I investigate what could be wrong here? Any kind of log or something?

编辑----------------------

EDIT ----------------------

如果我推送到repoRemote而不是demo上的master分支,则此问题已解决.为什么会这样?

The problem is fixed if I push to master branch on repoRemote, not demo. Why is so?

推荐答案

编辑,2016年12月:人们仍然在寻找这个旧答案,现在,三年后的今天,我真正理解了真正的问题是什么.当您使用接收后挂钩来部署多个不同的分支时,会发生此问题.如果仅从裸存储库部署一个分支,则问题将更少. Git不断发展,自动部署多个分支的最佳"解决方案可能会有所不同,具体取决于您所使用的Git版本.另请参见 Git接收后部署在随机点停止工作.

Edit, Dec 2016: people are still finding this old answer, and now, 3 years later, I truly understand what the real issue is. The problem occurs when you use a post-receive hook to deploy multiple different branches. If you only ever deploy one branch from a bare repository, you will have fewer problems. Git keeps evolving and the "best" solution for automatic deployment of several branches may vary depending on which Git version you have. See also Git post-receive deployment stops working at random points.

(下面的原始答案.)

我发现git checkout -f总是需要一个分支名称.允许它在裸存储库中使用HEAD并不是很可预测.

I've found that git checkout -f always needs a branch name; allowing it to use HEAD in bare repositories is not very predictable.

您可能还会遇到索引问题(git会在裸仓库中写一个,但有时会感到困惑). git checkout -f deployment-branch最好进入新的,空的新目录. (应该为每个部署分支设置一个索引文件,但我从未尝试过这样做.)

You may also run into issues with the index (git will write one in the bare repo, but it gets confused at times). It works best to git checkout -f deployment-branch into a new, fresh, empty directory. (It should work to set an index file per deployment-branch, I've just never gotten around to experimenting with this.)

如果您的裸仓库在除用于部署的分支之外的其他分支上都相当活跃,则最好用更高级的shell脚本包装代码,以检查所涉及的部署分支是否已真正更改.也就是说,如果有人更新了web-devel,则没有必要重新部署deployment-branch,这次他们没有进行更新.

If your bare repo will be fairly active on other branches than the one(s) used for deployment, it's a good idea to wrap the code with fancier shell-scripting that checks whether the deployment branch in question has actually been changed. That is, if someone updates web-devel, there's no point re-re-re-deploying deployment-branch, which they did not update this time.

这篇关于接收后挂钩失败-有机会看到原因吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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