使用 git 发布到网站
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4938239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using git to publish to a website
提问by Citizen
I used this guide to use git to autopublish my changes on my website when I push to my remote origin git repository:
当我推送到远程源 git 存储库时,我使用本指南使用 git 在我的网站上自动发布我的更改:
http://www.lwp.ca/james/2010/03/using-git-to-manage-online-website-projects/
http://www.lwp.ca/james/2010/03/using-git-to-manage-online-website-projects/
Here's my /hooks/post-update file:
这是我的 /hooks/post-update 文件:
cd ../../public_html/dir/wbg
env -i git pull
Here's my directory structure:
这是我的目录结构:
/home/git/wbg.git <-- my remote git repository
/home/git/wbg.git <-- 我的远程 git 存储库
/home/public_html/dir/wbg <-- my web folder
/home/public_html/dir/wbg <-- 我的网络文件夹
When I run
当我跑
git push origin master
The repository updates but my web folder is still empty. Any ideas?
存储库更新,但我的 web 文件夹仍然是空的。有任何想法吗?
Edit: if any future traffic sees this, my real problem was that BOTH your remote origin AND your destination website directory must be git repositories. You can't just set it up to copy your project to a new folder unless that folder is also a git repo.
编辑:如果任何未来的流量看到这一点,我真正的问题是您的远程源和目标网站目录都必须是 git 存储库。您不能将其设置为将项目复制到新文件夹,除非该文件夹也是 git 存储库。
采纳答案by mybuddymichael
Not a lot to go off of here, but I can report that I successfully use a similar method to this.
这里没什么好说的,但我可以报告说我成功地使用了与此类似的方法。
For my purposes, I call my bare server repository the "Hub" and my web-facing repository the "Prime". Make sure that you have properly initialized a git repository in your server htdocs directory (Prime) and have either pushed the changes to the bare repository (Hub) or pulled them in.
出于我的目的,我将我的裸服务器存储库称为“Hub”,将面向 Web 的存储库称为“Prime”。确保您已正确初始化服务器 htdocs 目录 (Prime) 中的 git 存储库,并将更改推送到裸存储库 (Hub) 或将其拉入。
This is the post-update
hook I use, which is in my Hub repository's hooks directory:
这是post-update
我使用的钩子,它在我的 Hub 存储库的钩子目录中:
#!/bin/sh
echo
echo "*** Pulling changes into Prime"
echo
cd /path/to/htdocs/ || exit
unset GIT_DIR
git pull hub master
exec git-update-server-info
Make sure this is executable! If in doubt, just edit the post-update.sample
file and remove the .sample
extension when done. The echoed text gives nice feedback that the copying is actually taking place. If you don't see that text, then it's not pulling the changes. And if you're not going to call your remote repository "hub", replace it with "origin" or whatever you decide to use.
确保这是可执行的!如果有疑问,只需编辑post-update.sample
文件并.sample
在完成后删除扩展名。回显的文本给出了很好的反馈,表明复制实际上正在发生。如果您没有看到该文本,那么它并没有拉动更改。如果您不打算将远程存储库称为“中心”,请将其替换为“来源”或您决定使用的任何内容。
As a precaution so that my Prime and local repositories don't get too out of whack, I have this as my Prime post-commit
hook:
作为预防措施,我的 Prime 和本地存储库不会太乱,我将它作为我的 Primepost-commit
钩子:
#!/bin/sh
echo
echo "*** Pushing changes to Hub"
echo
git push hub
Then I can just pull the changes from Hub into my local repository.
然后我可以将更改从 Hub 拉到我的本地存储库中。
回答by Arrowmaster
You can find a better alternative at http://toroid.org/ams/git-website-howtothat only uses one git repository, and allows all metadata and previous history to remain outside of the DocumentRoot.
您可以在http://toroid.org/ams/git-website-howto找到一个更好的替代方案,它只使用一个 git 存储库,并允许所有元数据和以前的历史记录保留在 DocumentRoot 之外。
The guide you used and the one I linked referrer to another article both are based on, but the one I linked seems to be the preferred one to direct new users to in the #git IRC channel.
您使用的指南和我将referrer 链接到另一篇文章的指南都基于,但我链接的指南似乎是将新用户引导到#git IRC 频道的首选指南。
回答by Giles Bathgate
You might start by getting post-update to echo some debugging output. Both standard output and standard error output are forwarded to git send-pack on the other end, so you can simply echo messages and you will see these on the client that you did git push. I assume you followed the guide to the word, made the post-update script executable, cloned the repo to the web folder etc.
您可以先获取更新后以回显一些调试输出。标准输出和标准错误输出都被转发到另一端的 git send-pack,所以你可以简单地回显消息,你会在客户端上看到这些是你执行 git push 的。我假设您遵循了该词的指南,使更新后脚本可执行,将 repo 克隆到 web 文件夹等。