如何公开使用子模块,但在本地符号链接到单个克隆? [英] How to use submodules publicly, but symlinks to a single clone locally?

查看:50
本文介绍了如何公开使用子模块,但在本地符号链接到单个克隆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次体验Git子模块.

I'm having my first Git Submodule experience.

我有一些项目依赖于同一子项目.我使这些项目保持同步,因此我正在使用子模块分支"功能(例如 git子模块添加-b主[URL] ).

I have some projects that depend on the same subproject. I keep these projects in sync, so I'm using the "submodule branch" feature (e.g. git submodule add -b master [URL]).

虽然我希望公共GitHub存储库传达子模块关系,但在我自己的工作流程中,我真的很想在磁盘上复制一个共享代码库.我以为我可以先设置子模块,然后使用符号链接进行切换.但是当我这样做时,我得到了:

While I'd like the public GitHub repositories to convey the submodule relationship, in my own workflow I'd really just like to have one clone of the shared codebase on my disk. I thought I could just set up the submodules, and then do a switcheroo with a symbolic link. But when I do, I get this:

On branch master
Changes not staged for commit:
 (use "git add <file>..." to update what will be committed)
 (use "git checkout -- <file>..." to discard changes in working directory)

    typechange: draem

因此,Git显然看到了它是符号链接的事实,而不是直接进入目录.

So Git apparently sees the fact that it's a symbolic link, instead of following through to the directory.

有没有可以使用子模块的工作流程,但实际上我的本地文件系统上只有一个克隆?

Is there any workflow where I can appear to be working with submodules, but really only have one clone on my local filesystem?

推荐答案

因此,Git显然看到了它是符号链接的事实,而不是直接进入目录.

So Git apparently sees the fact that it's a symbolic link, instead of following through to the directory.

是的,Git会看到这样的变化,因为该子模块在父存储库中声明为 特殊条目 索引 中的a> .

Yes, Git would see such a change, because that submodule is declared in the parent repo as a special entry in the index.

进行符号链接会将特殊条目替换为其他类型的文件.

Making a symlink would replace that special entry by a file of another type.

可以要做的是尝试使用 GIT_WORK_TREE 进行游戏(如"在git checkout中将子模块包括到钩子中的 GIT_WORK_TREE ).

What you could do is try playing with GIT_WORK_TREE (as in "Including submodules in git checkout to GIT_WORK_TREE in hook").

但是更简单的解决方案是:

But a more simpler solution would be to:

  • 将子模块放在正确的位置.
  • 在所需的子模块存储库中添加另一个克隆(/path/to/sub ).
  • 从父存储库中重复的子模块文件夹中以 git --work-tree =/path/to/sub 状态检测原始子模块文件夹中的所有更改.
  • keep your submodule right where they are.
  • add another clone of that submodule repo where you want it (/path/to/sub).
  • detect any changes from the original submodule folder with a git --work-tree=/path/to/sub status from within your duplicated submodule folder in your parent repos.

这篇关于如何公开使用子模块,但在本地符号链接到单个克隆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆