如何获取git以添加已经在另一个git存储库下跟踪的文件? [英] How can I get git to add files already tracked under another git repository?

查看:96
本文介绍了如何获取git以添加已经在另一个git存储库下跟踪的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某个目录中创建一个git存储库.将所有文件添加到该目录中并提交.然后在父目录中创建另一个git存储库并添加所有文件.在其他地方克隆该存储库.请注意,克隆的存储库中缺少子存储库中的文件.如何获得Git在嵌套存储库中添加所有文件?请注意,我不需要子模块-我也希望添加嵌套存储库中的文件.

Create a git repository in some directory. Add all the files in that directory and commit them. Then create another git repository in a parent directory and add all files. Clone that repository elsewhere. Note that the files in the sub-repository are missing in the cloned repository. How can I get Git to add all files in the nested repository? Note that I don't want submodules - I want the files from the nested repository to be added as well.

推荐答案

有可能您确实想要一些非常类似于子模块的东西(但可能不需要文字子模块).例如,一个大型项目由一定数量的N个子项目组成(N> 1),这似乎很普遍,出于良好的来源和/或组织方面的原因,每个子项目都应该有自己的git.回购.

Chances are that you do want something very much like submodules (but perhaps not literal submodules). For instance, it seems to be fairly common to have a large project that consists of some number N of sub-projects (N > 1), where, for good source and/or organizational reasons, each sub-project should have its own git repo.

子模块允许您拥有一个大的超级容器",该容器可以简单地调用所有子模块:

Submodules allow you to have one big "super-container" that simply calls out all the submodules:

super
    sub1
    sub2
    sub3

每个子模块在这里都是独立的(据其了解/关心),而"super"仅收集这三个子模块.

Here each submodule is independent (as far as it knows / cares, anyway) and "super" just collects the three.

问题在于,在开发过程中,您经常(但不总是)想要从每个子项目中获取分支devel上的最新信息".但是,子模块跟踪特定的提交-提交sub1的e01ab7c,sub2的58125f7等,这可能不是最新的".当然,您可以进入每个子项目并使用"git co devel"移动分支,然后转到超级项目并修复每个子模块以指向该子模块,但是如果您可以告诉git一定会很方便. 只是让我了解每个子模块的分支devel的技巧".

The catch is that during development, you often (but not always) want, e.g., "whatever is latest on branch devel" from every subproject. Submodules, however, track specific commits—commit e01ab7c of sub1, 58125f7 of sub2, etc., which may not be "the latest". You can of course go into each sub-project and "git co devel" to move the branch, then to go to the super-project and fix up each submodule to point to that, but it sure would be convenient if you could tell git "just get me the tip of branch devel of every submodule".

但是git不会那样做.相反,我们使用了一个庞大的(有些不稳定的)脚本来实现这些目标. (它还会收集跨越多个子模块的提交,因为有时更改会影响例如上述示例中的sub1sub3.)

But git won't do that. We use a massive (and somewhat flaky) script to achieve something along these lines instead. (It also collects commits that span multiple submodules, since sometimes a change affects, e.g., both sub1 and sub3 in the above kind of example.)

这篇关于如何获取git以添加已经在另一个git存储库下跟踪的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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