【问题标题】:Handling two repos like two branches in Git像 Git 中的两个分支一样处理两个存储库
【发布时间】:2016-05-10 00:54:16
【问题描述】:
repository A (already existing)
examples\

repository B (already existing)
code\
test\

尝试执行以下操作 - repo A 应该是 repo B 的一部分。它的 repo B 应该看起来像 -

repository B 
code\ 
test\ 
examples\ 

我们希望将这两个存储库分开。 用户应该能够独立地提交它们。 如果需要,可以将 repo A 合并到 repo B,反之亦然。 我可以想到子模块,但有没有不同的方法可以做到这一点。 我可以在 repo B 中克隆 repo A,保留两个存储库并推送到同一个远程。使用分支名称作为存储库?

【问题讨论】:

    标签: git github build-system


    【解决方案1】:

    没有。子模块是唯一接近这一点的东西,它需要单独的目录。一个目录中只有一个.git 目录(存储库),它包含repoA 或repoB,而不是两者。

    【讨论】:

      【解决方案2】:

      您还可以查看git-repo tool 以保持存储库拆分,然后在下载后将它们移动到正确的位置。清单格式可用here

      【讨论】:

        【解决方案3】:

        保留单个.git 的一种更简单(比子模块)的方法是 git subtree,但这也需要单独的目录。

        在回购 B 中工作

        git remote add repoA url.for.A
        git subtree add --prefix=examples/ repoA master
        

        在提示符中键入 git subtree 会提供一个很好的使用摘要。

        合并、拉取和推送都是可能的。请注意,尽管并非绝对必要,但最佳实践是 在子树和主树之间保持提交拆分(不要将对路径 examples/ 的提交与对其他两个的提交混合)以便提交日志仍然有意义。

        引用git subtree的帮助:

        [TIP]
        In order to keep your commit messages clean, we recommend that
        people split their commits between the subtrees and the main
        project as much as possible.  That is, if you make a change that
        affects both the library and the main application, commit it in
        two pieces.  That way, when you split the library commits out
        later, their descriptions will still make sense.  But if this
        isn't important to you, it's not *necessary*.  git subtree will
        simply leave out the non-library-related parts of the commit
        when it splits it out into the subproject later.
        

        【讨论】:

        • 谢谢。这看起来可能对我有用。在我继续之前,您能否详细说明保持提交路径分开。我不完全明白。谢谢!
        • 感谢您的提问。这更像是一个建议而不是必须做的。澄清并添加参考
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-03-25
        • 2014-10-02
        • 2023-03-27
        • 2010-09-19
        • 2010-09-30
        • 1970-01-01
        • 2020-04-06
        相关资源
        最近更新 更多