GIT 后接收挂钩未检出子模块

发布于 2024-11-14 16:00:57 字数 871 浏览 1 评论 0原文

我一直在开发 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

胡大本事 2024-11-21 16:00:57

您必须添加以下内容(适当使用 GIT_WORK_TREE 环境变量):

git submodule init
git submodule update

以便您可以获取远程服务器上子模块的内容,然后将它们复制到 public_html

下面是完整的接收后内容钩子(修改为支持子模块的正常运行):

#!/bin/sh
unset GIT_DIR
git clone /path/to/repo /tmp/public_html
cd /tmp/public_html
git submodule init
git submodule update
cp -R /tmp/public_html /var/www/
rm -rf /tmp/public_html
rm -rf /var/www/public_html/.git

You have to add the following (appropriately using the GIT_WORK_TREE environment varible):

git submodule init
git submodule update

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) :

#!/bin/sh
unset GIT_DIR
git clone /path/to/repo /tmp/public_html
cd /tmp/public_html
git submodule init
git submodule update
cp -R /tmp/public_html /var/www/
rm -rf /tmp/public_html
rm -rf /var/www/public_html/.git
﹉夏雨初晴づ 2024-11-21 16:00:57

这是我的接收后挂钩:
将 WORK_DIR 替换为您要签出的位置。就我而言,这是一个主 Web 目录。它被初始化为 git 存储库,并简单地从该钩子运行的 git 裸存储库中提取。这解决了签出速度问题(git 签出速度比其他答案中的 cp -R 快得多),并且还保持子模块正确同步。

#!/bin/sh
unset GIT_DIR
echo "Checking out"
(cd $WORK_DIR && git pull --recurse-submodules=yes --force)
echo "Submodule update..."
(cd $WORK_DIR && git --work-tree="$WORK_DIR" submodule update --init --recursive --force)

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.

#!/bin/sh
unset GIT_DIR
echo "Checking out"
(cd $WORK_DIR && git pull --recurse-submodules=yes --force)
echo "Submodule update..."
(cd $WORK_DIR && git --work-tree="$WORK_DIR" submodule update --init --recursive --force)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文