远程裸机上的Git子模块 [英] Git submodule on remote bare
问题描述
我已经设置了我的环境,所以我可以推送到远程裸仓库,我使用这些命令来设置远程仓库:
$ 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。
/ var / www / website
作为(非-bare)回购 post-receive
您裸露回购的挂钩:- 将
GIT_DIR
和GIT_WORK_TREE
设置为/ var / www / website
-
cd / var / ww / website
-
git pull〜/ website
-
git子模块更新
(有点像在如何在推送到裸露的工作目录之后在工作树中初始化/更新git子模块?)
换句话说:
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:
- to setup
/var/www/website
as a (non-bare) repo - have your
post-receive
hook of your bare repo:- set
GIT_DIR
andGIT_WORK_TREE
to the non-bare repo at/var/www/website
cd /var/ww/website
git pull ~/website
git submodule update
(a bit like in "How do I init/update a git submodule in a working tree after pushing to a bare working directory?")
- set
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屋!