从post接收挂钩更新Git子模块

从post接收挂钩更新Git子模块,git,mapping,hook,git-submodules,Git,Mapping,Hook,Git Submodules,我试图在每次提交到var/www超级项目时自动更新位于var/www/php/vendor/projectX中的子模块。我在.git/hooks/post-receive文件中添加了以下行: #!/bin/sh echo "Updating submodules recursively" pwd git submodule update --init --recursive 但当我致力于超级项目时,我得到了这个: Counting objects: 8, done. Delta compres

我试图在每次提交到
var/www
超级项目时自动更新位于
var/www/php/vendor/projectX
中的子模块。我在
.git/hooks/post-receive
文件中添加了以下行:

#!/bin/sh
echo "Updating submodules recursively"
pwd
git submodule update --init --recursive
但当我致力于超级项目时,我得到了这个:

Counting objects: 8, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 346 bytes | 0 bytes/s, done.
Total 4 (delta 3), reused 0 (delta 0)

remote: Updating submodules recursively
remote: /var/www/.git
remote: No submodule mapping found in .gitmodules for path 'php/vendor/projectX'
To www-data@11.22.33.44:.
3dc2404..bc46dd6  dev -> dev
但是,.gitmodules文件中有相应的部分,.git/modules中的文件也有相应的部分。手动运行
git子模块更新--init--recursive
可以正常工作。只有当从钩子里跑出来时,它才不起作用。谢谢你

试试看:

  • cd到该回购协议的根文件夹
  • 执行git命令时,指定该文件夹的工作树和git目录
这将在您的post接收钩子脚本中给出:

cd /var/www/
git --git-dir=/var/www/.git --work-tree=/var/www submodule update --init --recursive

非常感谢,它很有魅力。我花了很多时间寻找答案。如果你提供了
--work tree
,为什么有必要在文件夹中刻录光盘?@Clijsters 3年半后,我不太确定。我现在要写它
git-C/var/www submodule update--init--recursive
,但可能在当时,子模块只需要从根文件夹中使用。是的,git告诉我你是对的,有一些错误消息。谢谢这个答案帮助了我。我只是对此感到困惑,因为其他git语句在University中也有同样的问题,但是-C没有帮助。有线。