git 允许“裸”子模块吗?

Tyl*_*nin 6 git git-submodules git-bare

这可能很可怕,我不确定。

假设我们有一个带有工作目录的回购“产品”

/product
/product/command.script
/product/config/ (bare git repo)
Run Code Online (Sandbox Code Playgroud)

和一个带有工作目录的 repo "config"

/config
/config/config.json
Run Code Online (Sandbox Code Playgroud)

command.script 文件具有与裸存储库交互的操作。前任。运行 command.script BRANCH1 将运行命令

git show BRANCH1:config.json
Run Code Online (Sandbox Code Playgroud)

有什么办法可以让“/product/config/”文件夹成为“product”repo的子模块,这样当“product”repo被克隆时,“config”repo也将被克隆

git clone --bare [config origin here] config
Run Code Online (Sandbox Code Playgroud)

从它的来源开始,当“product”repo 被获取时,“/product/config”子模块可以被获取

git fetch origin '*:*'
Run Code Online (Sandbox Code Playgroud)

或者这是应该通过某种钩子处理的东西吗?

Von*_*onC 4

否:当获取存储库“产品”时,其索引将包含一个gitlink (记录子模块的 SHA1 的特殊条目)

该条目只能在非裸存储库中使用,以便作为嵌套(子模块)存储库进行扩展。

这就是为什么git clone手册页提到:

--recursive
--recurse-submodules
Run Code Online (Sandbox Code Playgroud)

创建克隆后,使用默认设置初始化其中的所有子模块。这相当于git submodule update --init --recursive克隆完成后立即运行。
如果克隆的存储库没有工作树/签出(即,如果给出 、 或 中的任何一个)--no-checkout/-n--bare则忽略此选项--mirror


这意味着最好config在正确的 SHA1(第一个product存储库中 gitlink 记录的)处单独克隆存储库(甚至是裸存储库),并git show BRANCH1:config.json在另一个克隆存储库中执行(使用git -C)。