git - 与 Visual Studio 存储库中的共享库

标签 git visual-studio-2015 repository shared subtree

我是 Git 版本控制的新手。我只希望每个项目都有自己的存储库。

我建立

  • RepoA中的一个项目(共享库)
  • RepoB 中具有 A
  • 子树的 B 项目(共享库)
  • RepoC 中具有 A
  • 子树的 C 项目(共享库)
  • 具有 B 和 C 子树的 RepoD 中的 D 项目(控制台应用程序)

  • 文件夹结构如下。

    D

    -B

    - 一种

    -C

    - 一种

    如您所见,一个文件夹被复制了,我不能在visual studio中两次添加同一个项目。

    如果我在 B 文件夹中添加 A 项目,则会发生编译错误。

    元数据文件项目 C..... 找不到“A.dll”
    因为C文件夹中的A项目,从来没有编译过,A.dll丢失了。

    如果 C 项目中的 A 编译一次,它可以正常工作。(通过在 C 项目中打开 C.sln 或 A.sln)
    当然会有A.dll,

    但是下次别人从git下载D项目时,他/她应该在编译D项目之前在C项目中编译C或A。

    有人对此有很好的解决方案吗?

    最佳答案

    您可以尝试阅读有关子模块的信息。

    Submodules allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, always pointed at a particular commit.



    git submodule
    像迄今为止所做的那样,将您的大项目分解为子项目。
    现在使用以下命令将每个子项目添加到您的主项目:
    git submodule add <url>
    
    一旦将投影添加到您的存储库中,您必须初始化并更新它。
    git submodule init
    git submodule update
    
    截至 Git 1.8.2 新选项 --remote加入
    git submodule update --remote --merge
    
    fetch 每个子模块中来自上游的最新更改, merge them in , 和 check out 子模块的最新版本。
    the docs形容它:

    --remote

    This option is only valid for the update command. Instead of using the superproject’s recorded SHA-1 to update the submodule, use the status of the submodule’s remote-tracking branch.


    这相当于在每个子模块中运行 git pull。

    However, how would I push a commit in the scenario of bug fix in C which affects the code shared with the parent layers?


    同样:使用子模块会将您的代码作为其内容的一部分放在主项目中。将其本地保存在文件夹中或将其作为子模块的一部分之间的区别在于,在子模块中,内容被管理(提交)到不同的独立存储库。

    这是子模块的图示 - 另一个项目中的项目,其中每个项目都是一个独立的项目。
    enter image description here

    git subtree
    Git 子树允许您插入任何存储库作为另一个存储库的子目录
    非常类似于 submodule但主要区别在于管理代码的位置。在子模块中,内容被放置在一个单独的存储库中并在那里进行管理,这允许您将其克隆到许多其他存储库。
    subtree 将内容作为根项目的一部分进行管理,而不是在单独的项目中。
    无需写下如何设置它以及了解如何使用它,您只需阅读这篇将解释一切的优秀文章即可。
    https://developer.atlassian.com/blog/2015/05/the-power-of-git-subtree/

    关于git - 与 Visual Studio 存储库中的共享库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36295207/

    相关文章:

    git - 在 Git 中,我如何确定我当前的版本是什么?

    visual-studio - Visual Studio Community 版本是否支持 Visual Studio Tools for Office (VSTO)?加载项设计器未显示

    maven - 内部 Maven 存储库索引不会在 m2eclipse 中更新

    intellij-idea - IntelliJ中的Gradlebuild设置

    github - 当你公开一个私有(private)仓库时,你在私有(private)时所做的提交会公开吗?

    git - 在 Github 上处理废弃的 pull 请求(保留历史记录)

    git - rebase 到没有共同祖先的分支

    git - 使用 `git push`恢复远程仓库可以吗?

    c# - 无法更改 VS 2015 C++ 项目中的 .NET 目标框架版本

    c++ - 'TypeInfo<char>(char * )' isn' t defined but worked pre-C++11; what changed, and how can I fix the error?