使用GIT部署网站 [英] Using GIT to deploy website

查看:119
本文介绍了使用GIT部署网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了这篇优秀的文章 http://toroid.org/ams/git-website



我有一个更新后的文件,它看起来像像这样:

  GIT_WORK_TREE = / home / rajat / webapps /< project name> git checkout -f 

每次我将代码推送到 master 分支时,自动部署。我现在想要做的是让这个支持多个分支,所以:
$ b $ ol <$> b $ b

  • git push origin master -----> deploy代码到生产(/ home / rajat / webapps / production)

  • git push origin staging ---->将代码部署到分段(/ home / rajat / webapps / staging) >
  • git push origin test ---->部署代码以测试(/ home / rajat / webapps / test)


    为此,更新后的钩子需要了解哪个分支得到了更新。这是可能的吗?

    解决方案

    可以编写一个检测分支名称的更新后钩子。 $ b见灵感:



    一个例子(所有这些钩子都基于 git rev-parse ):

     #!/ bin / bash 
    while oldrev newrev refname
    do
    branch = $(git rev-parse --symbolic --abbrev-ref $ refname)
    if [master==$ branch];然后
    #做某事
    fi
    完成


    I have followed this excellent write up http://toroid.org/ams/git-website-howto to deploy code to my server using Git's post-hooks strategy.

    I have a post-update file that looks like this:

    GIT_WORK_TREE=/home/rajat/webapps/<project name> git checkout -f
    

    Everytime I push code to master branch, it gets auto deployed. What I want to do now is to make this support multiple branches, so that:

    1. git push origin master -----> deploys code to production (/home/rajat/webapps/production)
    2. git push origin staging ----> deploys code to staging (/home/rajat/webapps/staging)
    3. git push origin test ----> deploys code to test (/home/rajat/webapps/test)

    For this, the post-update hook needs to understand which branch got updated. Is this possible ?

    解决方案

    It is possible to write a post-update hook which detect the branch name.
    See for inspiration:

    As an example (all those hooks are based on git rev-parse):

    #!/bin/bash
    while read oldrev newrev refname
    do
        branch=$(git rev-parse --symbolic --abbrev-ref $refname)
        if [ "master" == "$branch" ]; then
            # Do something
        fi
    done
    

    这篇关于使用GIT部署网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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