GIT 后接收挂钩未检出子模块
我一直在开发 Kohana 3 项目,该项目是我不久前使用下载的 zip 文件安装的。我的远程服务器“project.git”上有一个 git 存储库,它检查对工作目录“public_html”的最新提交,我在其中测试应用程序
我的接收后挂钩文件
GIT_WORK_TREE=/var/www/public_html;
git checkout -f;
已经工作了几个月,直到我决定删除一些 kohana 文件夹并使用 git 子模块,这样我就可以通过 git 进行更新。
现在的问题是子模块不在工作目录中。我尝试在那里添加子模块,但“public_html”目录不是存储库。在“project.git”目录中,git 命令抛出一个错误,我必须在工作目录中执行它们。
当我提交时,如何修改我的钩子以签出子模块?
更新
根据@manojlds的建议: 我将它添加到钩子中,现在它看起来像这样:
GIT_WORK_TREE=/var/www/public_html;
git submodule init;
git submodule update;
git checkout -f;
但是我收到此消息,
remote: You need to run this command from the Top level of the working tree
并且没有对子模块进行任何更改
public_html
I have been working on a Kohana 3 project that I installed using the downloaded zip file awhile ago. I have a git repository on my remote server "project.git" which checks out the latest commits to the working directory "public_html" where I test the application
My post-receive hook file
GIT_WORK_TREE=/var/www/public_html;
git checkout -f;
which was working for a couple of months until I decided to remove some kohana folders and use git submodule instead, so I can do updates via git.
Now the problem is that the submodules are not in the working directory. I tried going in there to add the submodules but the "public_html" directory isn't a repository. In the "project.git" directory, git commands throw an error that I must perform them in the working directory.
How do I modify my hook to checkout submodules when I do a commit?
Update
As per @manojlds's suggestion:
I added it to the hook and now it looks like this:
GIT_WORK_TREE=/var/www/public_html;
git submodule init;
git submodule update;
git checkout -f;
But I get this message,
remote: You need to run this command from the Top level of the working tree
and no changes to the submodules in
public_html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须添加以下内容(适当使用 GIT_WORK_TREE 环境变量):
以便您可以获取远程服务器上子模块的内容,然后将它们复制到
public_html
下面是完整的接收后内容钩子(修改为支持子模块的正常运行):
You have to add the following (appropriately using the GIT_WORK_TREE environment varible):
so that you can get the contents of the submodules on the remote server and then copy them to
public_html
The below is the full post-receive hook ( modified to support proper functioning of the submodules) :
这是我的接收后挂钩:
将 WORK_DIR 替换为您要签出的位置。就我而言,这是一个主 Web 目录。它被初始化为 git 存储库,并简单地从该钩子运行的 git 裸存储库中提取。这解决了签出速度问题(git 签出速度比其他答案中的 cp -R 快得多),并且还保持子模块正确同步。
This is my post-receive hook:
Replace WORK_DIR with a location where you want to checkout to. This is a main web directory in my case. It is initialized as a git repository and simply pulls from the git bare repository this hooks runs in. This solves both the checkout speed (git is much faster in checking out than cp -R from the other answer is) and also keeps submodules properly synced.