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

问题描述

我遵循了这篇优秀的文章




  • 一个例子(所有这些钩子都基于):

     #!/ 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部署网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-05 12:39
    查看更多