远程裸机上的Git子模块 [英] Git submodule on remote bare

查看:88
本文介绍了远程裸机上的Git子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了我的环境,所以我可以推送到远程裸仓库,我使用这些命令来设置远程仓库:

  $ mkdir〜/ website.git&& cd〜/ website.git 
$ git init --bare

  $ cat> hooks / post-receive 

#!/ bin / sh
GIT_WORK_TREE = / var / www / website git checkout -f
$ b $ chmod + x hooks / post - 接收

并且在我的本地环境中:

  $ git remote add web ssh://website.com/home/website.git 
$ git push web + master:refs / heads / master

现在我可以使用 git push web 工程很棒..



问题:子模块



我有几个子模块在我的项目中,没有在远程仓库初始化/更新的gettin ...我不能在裸露的地方运行 git submodule update ,因为它是裸露的,在 / var / www / website 文件夹中运行它,因为它只是文件的副本而不是git repo。

$ b $ ul
  • 设置 / var / www / website 作为(非-bare)回购

  • 有您的 post-receive 您裸露回购的挂钩:




  • 换句话说:

    Pull从裸回购,而不是尝试从裸回购结算:非裸回购应该能够容纳 git子模块更新步骤。



    一个示例脚本可能看起来像

     #!/ bin / sh 

    #获取最新的代码
    cd / path / to / bare / repo
    git fetch

    #设置git变量
    GIT_WORK_TREE = / var / www /网站
    GIT_DIR = / var / www / website / .git

    #进入网站并拉取
    cd / var / www / website
    git pull / path / to / bare / repo
    git子模块更新--init --recursive

    #在这里运行额外的构建函数


    I've setup my environment so I can push to a remote bare repository, I used these commands to setup the remote repository:

    $ mkdir ~/website.git && cd ~/website.git
    $ git init --bare
    

    And

    $ cat > hooks/post-receive
    
    #!/bin/sh
    GIT_WORK_TREE=/var/www/website git checkout -f
    
    $ chmod +x hooks/post-receive
    

    And on my local environment:

    $ git remote add web ssh://website.com/home/website.git
    $ git push web +master:refs/heads/master
    

    Now i can deploy to this remote using git push web and everything works great..

    The problem: Submodules

    I have a few submodules on my project that aren't gettin initialized/updated at the remote repository... I can't run git submodule update on the bare because it's bare, and I can't run it on the /var/www/website folder because it's just a copy of the files and not a git repo.

    解决方案

    One possible way might be:

    In other words:
    Pull from the bare repo instead of trying to checkout from a bare repo: a non-bare repo should be able then to accommodate the git submodule update step.

    An example script may look like

    #!/bin/sh
    
    # Get the latest code
    cd /path/to/bare/repo
    git fetch
    
    # Set git variables
    GIT_WORK_TREE=/var/www/website
    GIT_DIR=/var/www/website/.git
    
    # Go to website and pull
    cd /var/www/website
    git pull /path/to/bare/repo
    git submodule update --init --recursive
    
    # Run additional build stuff here
    

    这篇关于远程裸机上的Git子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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