用于网站登台的 Git Post-Receive Hook [英] Git Post-Receive Hook for Website Staging

查看:23
本文介绍了用于网站登台的 Git Post-Receive Hook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置 Git 来暂存我的网站,以便我可以 git pull 使当前版本在本地运行,然后 git push 进行推送对远程服务器的更改.我已经设置好了它可以按照我想要的方式工作,但是在我推送之后,我必须手动运行 git checkout -fgit reset --hard HEAD 在远程服务器上.

I'm trying to set up Git for staging my website so that I can git pull to get the current version to work on locally and then git push to push the changes to the remote server. I've got it set up so that it works the way I want it to, but after I push, I have to manually run git checkout -f or git reset --hard HEAD on the remote server.

我已经尝试将它们作为服务器上的 post-receive hook 放入一个 shell 脚本中,但它似乎没有任何效果.我知道脚本正在运行,因为我在推送后看到更改已推送到服务器".这是 post-receive 钩子:

I've tried putting these into a shell script as the post-receive hook on the server, but it just doesn't seem to have any effect. I know that the script is running because I'm seeing "Changes pushed to server" after I push. Here's the post-receive hook:

#!/bin/sh
git reset --hard HEAD
echo "Changes pushed to server."

推荐答案

您的问题的答案在这里:http://toroid.org/ams/git-website-howto

The answer to your question is here: http://toroid.org/ams/git-website-howto

简而言之,您要做的就是将分离的工作树"添加到裸存储库中.通常您认为您的工作树包含 .git 目录.根据定义,裸存储库没有工作树,但您可以创建一个,只要它与裸存储库位于不同的目录中.

In short, what you want to do is add a "detached work tree" to the bare repository. Normally you think of your work tree as containing the .git directory. Bare repositories do not have a work tree by definition, but you can create one as long as it's in a different directory than the bare repo.

post-receive hook 只是一个简单的 git checkout -f 来将存储库的 HEAD 复制到工作目录中.Apache 使用它作为它的文档根目录,一切就绪.每当您推送到裸存储库时,Apache 都会立即开始为其提供服务.

The post-receive hook is just a simple git checkout -f to replicate the repository's HEAD into the work directory. Apache uses that as its document root, and you're all set. Any time you push to the bare repository, Apache will immediately start serving it.

我通常使用它来自动推送到临时服务器,以查看真实"环境是否会影响我的更改.部署到实时服务器是一个完全不同的故事.:-)

I generally use this to automatically push to a staging server to see if the "real" environment will puke on my changes. Deploying to the live server is a completely different story. :-)

这篇关于用于网站登台的 Git Post-Receive Hook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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