gpt4 book ai didi

git - 重用 git 存储库的一部分

转载 作者:IT王子 更新时间:2023-10-29 01:03:56 26 4
gpt4 key购买 nike

我有以下项目设置:

  • Solution A
    • Project 1 (轻量级组件)
    • Project 2 (包含很多文件,依赖Project 1)

Solution A是一个单一的 git 存储库。然后我创建了另一个解决方案,发现我可以重用甚至更新 Project 1 的功能.所以我的第二个解决方案可能是这样的:

  • Solution B
    • Project 1 (必须分享!)
    • Project 3 (取决于 Project 1 )。

现在我要Project 1成为共享组件。也就是我每次改Project 1的源码从任一解决方案(AB),我需要另一个进行相应更新。

也许这与 gitsubmodule 特性有关。但是,我能够使用它的唯一方法是指定整个 Solution A作为 Solution B 的子模块.由于 Solution A 的巨大尺寸,这并不是我理想中想要的.我只需要它的一小部分成为子模块。

我知道这在 svn 中是可能的,并且完全按照我描述的方式工作:您在 svn:externals 中的外部存储库中指定一个目录。属性(property)。

有什么建议吗?或许,我遗漏了什么?

最佳答案

这肯定与子模块有关(参见 nature of submodules )

在您的情况下,理想的解决方案是从 SolutionA Git repo 中提取 Project1:
参见 How to extract a git subdirectory and make a submodule out of it? .

但这涉及到重写 SolutionA 的历史,如果您已经发布了它并且有人正在从中提取它,那么这就是一个问题。

使用 filter-branch用于提取过程。

To rewrite the repository to look as if Project1/ had been its project root, and discard all other history:

git filter-branch --subdirectory-filter Project1 -- --all

Thus you can, e.g., turn a library subdirectory into a repository of its own. Note the -- that separates filter-branch options from revision options, and the --all to rewrite all branches and tags.

然后将 Project1 声明为 SolutionB 中的子模块:

cd SolutionB
git submodule add /path/to/Project1 Project1

NOTE: Do not use local URLs here if you plan to publish your SolutionB!

git commit -m "Add submodules Project1"

关于git - 重用 git 存储库的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2326299/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com