如何访问git服务器的不同分支


How to visit different branches of a git server?

我的问题的一些关键词

Nginx通配符域名,git

我不知道这个翻译是否正确,用我的母语来说是泛域名

问题:Nginx服务器上有几个GIT分支,我想通过键入URL xxx.example.com/来访问每个分支的代码,其中xxx是分支名称的名称。

我想我的服务器上可能应该有几个文件夹,每个文件夹都是一个git分支,所以我可以通过Nginx配置、的路由访问每个分支的代码

我应该如何创建每个分支的代码都可以访问的文件夹?当我推送到master分支时,如何刷新所有代码?

我只知道我的问题和GIT HOOKS之间有一些关系我应该配置Nginx服务器,这样不同的url就可以指向我服务器上的不同文件夹。

也许服务器的结构是这样的:

  • 船长
    • .git
    • index.php
    • 其他
  • AAA
    • index.php
    • 其他
  • BBB
    • index.php
    • 其他

AAA与master的AAA分支具有相同的代码。

BBB与主的BBB分支具有相同的代码

我得到了朋友的帮助,它很有效,实际上我的问题可以简化为两部分:

1.生成每个数字分支代码

2.为每个分支机构的项目配置不同的路径。

我要解决第一个问题。

git分支示例

正如我提到的第一个问题是关于"git hooks",思路是每次发生"pull操作"时都要检查分支的代码,shell可以通过使用git hook自动运行,git Hook位于中

.git/hooks/

已经存在一些示例,我们可以通过删除扩展名来启动这些shell。示例,例如post-rereceive文件,这个文件在完成git pull操作后运行,这里是签出每个分支代码的方法:(写入post-rereceivefile,请修改您的路径)

#!/bin/sh
#-------------- For Visiting branches --------------
#--The stucture of project
#--    -serverFolder
#--      -.git
#--        -hooks
#--        -info
#--        -branchProject
#--          -221
#--            -.git
#--            -application
#--            -system
#--            -others
#--          -222
#--            -.git
#--            -application
#--            -system
#--            -others
#--      -application
#--      -system
#--      -others
#--      
#--------------------------------------------
DST_DIR="branchPorject"
CLONE_PATH="your remote project path"
read oldrev newrev
ver=$(echo $newrev | cut -d "/" -f 3)
dst_path=$DST_DIR/${ver//'./""}
if [ ! -d $dst_path ];then
    mkdir -p $dst_path
    chmod -R 775 $DST_DIR
    chmod -R 775 $dst_path
    cd $dst_path
    env -i git clone $CLONE_PATH  #$dst_path
    env -i git config --add core.filemode false
fi
###################################################
# deploy
cd $dst_path
is_bare=$(git config --get --bool core.bare)
if [ "$is_bare" == "true" ];then
    echo "ERROR: only not bare repo can deploy"
    exit 1
fi
env -i git checkout $ver
env -i git pull
env -i chmod -R 775 $dst_path

现在我们在.git文件夹中有了分支221和分支222的项目,结构显示在后面的shell中。通过配置nginx或apache重写规则,我们可以通过浏览器访问不同的分支,也许可以键入这样的URL来访问它们:

http://example.221.com
http://example.222.com
http://example.master.com

我认为这对网络项目测试很方便。