刚刚创建了带有两个子模块的新存储库。它在本地运行良好,但在推向生产环境时,子模块不存在。每个子模块的根目录都存在,但是里面没有文件
git version 2.27.0
创建生产仓库
git --bare init
cd hooks && touch post-receive && chmod +x post-receive
cat hooks/post-receive
#/bin/sh
git --work-tree=/var/www/repo --git-dir=/var/git_repos/repo.git checkout -f
从开发/本地推向生产
git push production master
git status
告诉一切都是最新的。即使在子模块文件夹中调用它。尝试删除本地存储库上的submodule文件夹,提交/推送到存储库。然后git push production master
,根子模块文件夹在生产服务器上被删除。然后尝试再次添加
# git submodule add [email protected]:alias/repo_name.git php/repo/repo_name
Cloning into '/var/www/project/php/repo/repo_name'...
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 19 (delta 8), reused 19 (delta 8), pack-reused 0
Receiving objects: 100% (19/19), 8.62 KiB | 8.62 MiB/s, done.
Resolving deltas: 100% (8/8), done.
然后提交到存储库,然后git push production master
。同样的问题。在生产中,存在子模块的根文件夹,但目录中没有文件。
当我在github上浏览存储库时,子模块已正确链接。
一切都在本地存储库中运行
子模块文件夹在github(或本地存储库)上不是空的,但是当推送到生产环境时,它们是
可以预期:子模块由以下组成:
.gitmodules
gitlink
,索引中的特殊条目,代表子模块存储库的根树的SHA1。当您使用子模块克隆远程存储库时(使用该git clone --recurse-submodules
选项),这些子模块存储库将被自身克隆,并在该gitlink表示的SHA1处检出。
“推入生产”非常棘手,因为您不应该将其推入已检出(非裸露)的存储库(即使您从技术上来说也可以这样做)。
最好将其推送到生产环境中的裸存储库,该存储库将使用接收后钩子来还原文件(包括使用的子模块内容git restore --recurse-submodules
)
经过讨论:
您需要生产服务器将公共SSH密钥注册到您的帐户中,因为子模块是.gitmodules
使用SSH URL注册的。
接收后脚本变为:
#!/bin/bash
cd /var/www/repo
git --git-dir=/var/git_repos/repo.git --work-tree=. restore --recurse-submodules :/
这意味着,如果涉及子模块,则当前文件夹必须是工作树。
然后,你可以做的命令喜欢git checkout
/git restore
有--recurse-submodules
,或者git submodule update --init
,即使有不同的git-DIR( --git-dir=/path/to/bare/repo.git
)。
子模块将被更新,因为您当前的工作树就是正确的树。
如果你是不是在任何地方/var/www/repo
,即使你指定git --work-tree=/var/www/repo ...
,没有上述的命令git checkout
/git restore
用--recurse-submodules
,或git submodule update --init
会为你的回购的子模块的工作。
即:您的/var/www/repo
文件将被还原,但是子模块将保持为空。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句