Git 子模块和工作副本同时存在?

Git submodule and working copy at the same time?

我在 Git.

中有我的 .dotfiles(.zshrc、.bashrc 等)

我想在 plugins 子目录中有一些额外的存储库(也来自我)——我有一个自定义存储库用于我的 Emacs 配置,另一个用于我的 LaTeX 配置等。

将它们创建为子模块是否有意义?我的意思是:我也可以将其用作工作副本,并直接从子模块编辑我的 LaTeX 配置吗?

或者我在这里混合了一些东西? (对于每个子模块回购,我想避免在我的机器上有 2 个内容相同或几乎相同的目录——我希望我的子模块始终处于最新版本,或几乎是最新版本。)

更新

我在 /usr/me/.dotfiles.

中有我的主仓库(同时也是一个可编辑的工作副本)

如果我将子模块放在 /usr/me/.dotfiles/plugins 中(例如),我的优势是在克隆时可以将所有其他拼图一起提取,但我知道我不能直接编辑这些文件在那里,对吧?那么,这是一个问题...因为我确实有 "task files",例如,当我重新安排事情时编辑它们。

要正确编辑这些内容,我必须去 /usr/me/dev/repo-task-files...根本不实用...

现在,我可以将普通存储库放入 /usr/me/.dotfiles/plugins,但不能作为子模块。这意味着,在其他机器上,我必须手动(或通过脚本)在同一位置克隆不同的存储库,但这不是单行操作(在克隆点文件时)。

但是,然后,我可以直接在文件所在的位置进行编辑。

我的改进问题:上面的描述对吗?有第三种方法吗?

更新

Does it make sense to create those as submodules? I mean: can I use that as a working copy as well, and directly edit my LaTeX config from the submodule?

是的,子模块旨在用作独立的存储库。在子模块内提交更改与在 repo 的另一个本地副本中进行更改完全相同。唯一的区别是您将在超级仓库中进行未提交的更改。

If I put submodules in /usr/me/.dotfiles/plugins (for example), I have the advantage of having all the other puzzle pieces fetched at one, when cloning, but I understand that I can't edit those files directly in there, right?

您可以像编辑任何其他 git 存储库一样编辑子模块。

Now, I can just put the plain repos in /usr/me/.dotfiles/plugins, though not as submodules. It means that, on other machines, I must manually (or via a script) clone the different repos in the same place, but it's not a one-line operation (when cloning dotfiles).

这种方法的问题是 "subrepo" 中的任何更改都会出现在两个存储库中。子项目的文件夹将被视为超级项目中的另一个跟踪目录。

当一个 repo 看到它的子模块发生变化时,它会报告一个修改过的文件:

$ git status
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)
  (commit or discard the untracked or modified content in submodules)

        modified:   plugins/LaTeX (new commits, modified content)

原回答

关于子模块的事情是您将存储库的特定版本绑定到超级项目。如果您继续开发子模块并做出会破坏父模块的更改怎么办?

通过使用子模块,您可以确保始终有一个可用的版本。

无论如何,您不应该关心在本地拥有多个存储库副本。

如果您担心在获取时浪费带宽,您可以将远程添加到指向其他本地副本的存储库。