Git Post-Receive挂钩用于网站分段 [英] Git Post-Receive Hook for Website Staging

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

问题描述

我试图设置Git来升级我的网站,以便我可以 git pull 来获取当前版本在本地运行,然后 git push 将更改推送到远程服务器。我已经设置了它,以便按照我希望的方式工作,但是在我推送后,我必须手动运行 git checkout -f git reset --hard HEAD 在远程服务器上。



我试过把这些放到shell脚本中作为post-receive钩在服务器上,但它似乎没有任何影响。我知道脚本正在运行,因为我看到推送到服务器的变化,我推动后。这里是post-receive钩子:

 #!/ bin / sh 
git reset --hard HEAD
回显更改推送到服务器。


解决方案

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



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



后接收钩是只需一个简单的 git checkout -f 即可将存储库的 HEAD 复制到工作目录中。 Apache使用它作为它的文档根目录,并且你全都设置好了。无论何时您推送到裸仓库,Apache都会立即开始提供服务。



我通常会使用它自动推送到临时服务器,以查看真实环境会呕吐我的变化。部署到实时服务器是一个完全不同的故事。 : - )

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.

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."

解决方案

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

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.

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挂钩用于网站分段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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