是否可以使用git push部署一个网站?我有一种预感,它与使用git挂钩来执行git重置有关——在服务器端很难,但我该如何完成这一点呢?


当前回答

对于有多个开发人员访问同一个存储库的环境,下面的指导方针可能会有所帮助。

确保你有一个所有开发人员都属于的unix组,并将.git存储库的所有权授予该组。

在服务器存储库的.git/config中设置sharerepository = true。(这告诉git允许提交和部署所需的多个用户。 将每个用户的bashrc文件中的umask设置为相同的- 002是一个很好的开始

其他回答

我在这个网站上找到了这个脚本,它似乎工作得很好。

复制你的。git目录到你的web服务器 在你的本地副本上,修改你的.git/config文件,并添加你的web服务器作为远程服务器: (远程“生产”) Url = username@webserver:/path/to/htdocs/.git 在服务器上,用这个文件替换。git/hooks/post-update(在下面的答案中) 添加对文件的执行访问(同样是在服务器上): Chmod +x .git/hooks/post-update 现在,只要本地推送到你的web服务器,它就会自动更新工作副本: Git推送生产

我们使用capistrano来管理部署。 我们构建capistrano以部署在登台服务器上,然后与我们所有的服务器运行rsync。

cap deploy
cap deploy:start_rsync (when the staging is ok)

使用capistrano,我们可以在出现bug时轻松回滚

cap deploy:rollback
cap deploy:start_rsync

我最终创建了我自己的基本部署工具,它会自动从repo - https://github.com/jesalg/SlimJim -下拉新的更新,基本上它会监听github的接收后钩子,并使用代理来触发更新脚本。

You could conceivably set up a git hook that when say a commit is made to say the "stable" branch it will pull the changes and apply them to the PHP site. The big downside is you won't have much control if something goes wrong and it will add time to your testing - but you can get an idea of how much work will be involved when you merge say your trunk branch into the stable branch to know how many conflicts you may run into. It will be important to keep an eye on any files that are site specific (eg. configuration files) unless you solely intend to only run the one site.

或者,你有没有考虑过把改变推到网站上?

有关git钩子的信息,请参阅githooks文档。

更新:我现在使用Lloyd Moore解决方案与密钥代理ssh -A ....推入一个主回购,然后从所有机器上并行地从主回购中提取,这稍微快一些,在这些机器上需要的设置也更少。


这里没有解。如果服务器上安装了git,只需通过SSH推送即可。

在本地的.git/配置中需要以下条目

[remote "amazon"]
    url = amazon:/path/to/project.git
    fetch = +refs/heads/*:refs/remotes/amazon/*

但是嘿,亚马逊是怎么回事?在你的本地~/。Ssh /config你需要添加以下条目:

Host amazon
    Hostname <YOUR_IP>
    User <USER>
    IdentityFile ~/.ssh/amazon-private-key

现在你可以打电话

git push amazon master
ssh <USER>@<YOUR_IP> 'cd /path/to/project && git pull'

(顺便说一句:/ /项目/路径。Git与实际的工作目录/路径/到/项目不同)