Git:有没有好的方法来管理同一个子模块的多个实例? 浅克隆方法工作树方法

问题描述

我有一个项目,它驻留在包含同一子模块的多个副本/实例的 git 存储库中。 子模块可以使用不同的稀疏检出配置检出(同一 repo 的)不同修订版。

是否有避免克隆/拉取冗余的好方法

浅克隆方法

我正在查看子模块的 shallow-clone 配置。这会导致 git 只获取分支的提示。 这是一个问题,因为我需要允许在子模块中检出旧版本。这样,当我落后时,我会收到未通告的对象错误

我可以在子模块中为每个实例维护一个远程分支,以始终指向签出的修订版。但这有点麻烦。

工作树方法

另一种选择是使用 git-worktree。 我受到这篇文章的启发,它描绘了一个不同的场景: Git: Possible to use same submodule working copy by multiple projects?

我试图制作一个主要的子模块,然后使用工作树实例而不是重复。 这在本地工作得很好,但我似乎无法与超级项目的其他克隆共享此功能

具有此实验性文件夹结构:

project/submodules/main
project/submodules/instance1
project/submodules/instance2
project/submodules/instance3

初始化子模块和工作树实例:

cd project/submodules
git submodule add SOME/URL main 
cd main
git worktree add ../instance1
git worktree add ../instance2
git worktree add ../instance3

然后我在 .git 文件夹中看到了这个:

project/.git/modules/main/worktrees/instance1
project/.git/modules/main/worktrees/instance2
project/.git/modules/main/worktrees/instance3

在提交这些时,我收到了这个警告:

warning: adding embedded git repository: instance1
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not kNow how to obtain it.
hint: If you meant to add a submodule,use:
hint:
hint:   git submodule add <url> instance1
hint:
hint: If you added this path by mistake,you can remove it from the
hint: index with:
hint:
hint:   git rm --cached instance1
hint:
hint: See "git help submodule" for more @R_84_4045@ion.

将这个项目克隆到另一个文件夹后,我看不到 .git 下的工作树文件夹,并且 instance1/2/3 文件夹是空的,无法填充它们。

最后,我的问题是:

  1. 有没有办法共享/提交/推送子模块工作树设置?
  2. 有没有一种方法可以使用浅克隆而不会在后面出现未通告的对象错误
  3. 是否有更好的方法来管理多个相同的子模块实例?
  4. 在脚本/git-hook 的情况下,有没有办法在没有用户明确操作的情况下在克隆时自动触发它?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)