git - 使用 EXACT 文件夹结构创建包含子模块的 EXACT git 存储库并将其推送到 github

标签 git github git-submodules

我认为我的可能是 git 子模块的最简单用例。

我有一个目录结构

<project-name>
 ---<directory1>
 ---<directory2>
 ---<directory3>
        ---<directory3.1>

每个子目录都是一个 git 存储库。我只想跟踪在我的 <project-name> 中添加的不同 git 存储库目录,这是我的主要(或 super )存储库。

我已经弄清楚如何将这些 git 存储库中的每一个作为子模块添加到我的 super 存储库中,这也是一个包含它们的目录。在本地,我有我想要的。

所以一些git子模块是我 super 仓库里面的两个深度,只要我用
git submodule add <relative-path-to-submodule> <relative-path-to-submodule>

它照顾得很好。

为什么我想这样做?因为这代表了 CFD 框架 (OpenFOAM) 中的传统本地目录结构,所以我正在开发我的代码。

我和其他人分别开发不同的子模块,单独跟踪每个子模块/子目录绝对有值(value)。

目标是让我的最终用户克隆我的代码存储库,更改名称并开始编译和使用代码。 (按照惯例, build 非常简单)

我只是不知道如何将所有代码推送到 github,包括来自
子模块作为该特定子目录中的文件。

显然,当我推送到 github 时,子模块只是作为提交出现,没有实际代码
子目录被推送。


我不想(不能)想在 super 存储库中添加子目录。所有答案都告诉我这样做,这是没有意义的。

我找到了确切的问题,没有答案(Git: Push a local git submodule, including submodule files, to a remote bare repository)

最佳答案

I just can't figure out how to push all the code to github, including the actual files from the submodule as files in that particular subdirectory.



首先,不要使用子模块,它们不适合你想做的事情。

二、尝试子树方法:我解释了区别between submodule and subtree , 和 illustrated subtree here .

看:
  • The power of Git subtree”,作者 Nicola Paolucci。
  • "Git subtree: the alternative to Git submodule "

  • git subtree lets you nest one repository inside another as a sub-directory. It is one of several ways Git projects can manage project dependencies.



    https://wac-cdn.atlassian.com/dam/jcr:f5fcef58-5b93-4ff4-b9a1-3f721d29ead8/BeforeAfterGitSubtreeDiagram.png?cdnVersion=685

    关于git - 使用 EXACT 文件夹结构创建包含子模块的 EXACT git 存储库并将其推送到 github,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58907021/

    相关文章:

    java - 如何更新当前项目在github上的仓库?

    html - google maps javascript api-key (v3) 是否需要在检查到 github 的 HTML 中保密,如果是,如何?

    git - bundler : `bundle package` 带有 :git 源

    ruby - 要点没有得到颜色编码

    git - 将 Git 子模块设置为浅克隆和稀疏 checkout ?

    git - git如何在另一个分支下创建一个分支?

    node.js - 在 Heroku 推送上设置 `process.env.commit`

    git - 将 git repo 转换为子模块

    python - Conda 将一个 environment.yml 导入另一个

    git - 如何将标签推送到gerrit中的特定分支