简体   繁体   English

如何设置我的git存储库以便轻松地在Visual Studio中重用项目

[英]How do I set up my git repositories to easily be able to reuse projects in Visual Studio

My problem may be best described with an example. 我的问题最好用一个例子来描述。

Assume I have a project "A". 假设我有一个项目“A”。

I also have a project "B" which depends on "A". 我还有一个项目“B”,它取决于“A”。

Another project "C" also depends on "A". 另一个项目“C”也取决于“A”。

My "main" project depends on "B" and "C". 我的“主要”项目取决于“B”和“C”。 It may also be that it also depends directly on "A". 它也可能直接取决于“A”。

Looks a bit like the "dreaded diamond of inheritance" when "main" == "D" 当“主要”==“D”时,看起来有点像“可怕的继承钻石

可怕的继承钻石

These are my requirements: 这些是我的要求:

  • I'd like to be able to edit the content of projects "A", "B" and "C" in the solution for "main " and submit changes (ie I don't want just to include the DLL but also the code). 我希望能够在“main”的解决方案中编辑项目“A”,“B”和“C”的内容并提交更改(即我不想只包含DLL而是代码)。 But since "B" and "C" both depend on "A", it should be enforced that they reference the same commit. 但由于“B”和“C”都依赖于“A”,因此应该强制它们引用相同的提交。

  • The projects "A", "B" and "C" will most likely also be referenced by other projects, so I cannot assume ownership of the working directory for project "main". 项目“A”,“B”和“C”很可能也会被其他项目引用,因此我不能假设项目“main”的工作目录的所有权。

  • Also it should be possible to sync the repositories for each project with external repositories. 此外,应该可以将每个项目的存储库与外部存储库同步。

  • The projects "A", "B", "C" and "main" should be 项目“A”,“B”,“C”和“主要”应该是

How do I need to set up my repositories to accomplish this? 我如何设置我的存储库来完成此任务?

Do not (ab)use git or any version control system for this. 不要(ab)使用git或任何版本控制系统。

Use NuGet . 使用NuGet

You don't want to directly include other projects. 您不希望直接包含其他项目。 Instead, pack every dependency into a .nuget package and use that for dependency handling. 相反,将每个依赖项打包到.nuget包中,并将其用于依赖项处理。 While submodules seems a solution to the problem, in practice, you are much better off using a proper dependency management instead of just including other projects. 虽然子模块似乎是问题的解决方案,但在实践中,使用适当的依赖关系管理而不仅仅包括其他项目要好得多。

TeamCity and other CI systems, even TFS, allow you to automatically build new nuget packages, and TeamCity can also act as a nuget server. TeamCity和其他CI系统,甚至TFS,允许您自动构建新的nuget包,TeamCity也可以充当nuget服务器。

And if you do not want to use a 'real' NuGet server, you can also just use a shared drive somewhere on your intranet. 如果您不想使用“真正的”NuGet服务器,您也可以在Intranet上的某个位置使用共享驱动器。

Using the submodules approach , I would recommend a model which includes a list of dependencies, instead of a hierarchy of dependencies: 使用子模块方法 ,我建议使用包含依赖项列表的模型,而不是依赖项层次结构:

Create a " parent " repo, in which you " git submodule add " the submodules for D , C , B and A : 创建一个“ parent ”仓库,在其中“ git submodule addDCBA的子模块:

parent
  D
  C
  B
  A

Add any symlink ( even in Windows ) you need for each project to compile (meaning to find the sources for their dependencies right from within there own structure). 添加编译每个项目所需的任何符号链接( 即使在Windows中 )(意味着从自己的结构中查找其依赖项的源)。

The " parent " repo will reference the exact list of SHA1 representing each dependencies at their exact version needed for the project to compile/run at a specific time in the history of the parent repo. parent ”repo将引用表示每个依赖项的SHA1的确切列表,其中包含项目在父repo历史记录中的特定时间编译/运行所需的确切版本。

And, as I explain in " true nature of submodules ", you can make any modification you want in A , B , C or D , and push to their respective upstream repo . 而且,正如我在“ 子模块的真实性质 ”中所解释的那样,您可以在ABCD进行任何修改,并推送到各自的上游回购
But you must not forget to go back to the parent repo, add and commit the SHA1 modifications representing the new state of the dependent repos A , B , C , and D . 但是你不能忘记回到parent repo,添加并提交表示依赖回购ABCD的新状态的SHA1修改。

This is a component approach , which has the advantage of resolving any overlapping dependency: if B and C need a different version of A , the parent repo will have to chose one (and only one) version of A . 这是一个组件的方法 ,其具有解决任何重叠依赖性的优势在于:如果BC需要不同版本的A ,所述parent回购将必须选择一个(并且只有一个)的版本A

To add to the OP Onur's answer: 要添加OP Onur的答案:

Dependencies must be relative 依赖关系必须是相对的

Not necessarily: you can add symlink within a submodule, if it needs to see another with a fixed path. 不一定:您可以在子模块中添加符号链接,如果它需要查看另一个具有固定路径的符号链接。

Create the " user " repository 创建“ user ”存储库

How do I automatically check out the correct set of libraries, eg A and B in the setup above 如何自动检出正确的库集,例如上面的设置中的A和B.

Once you have determined valid starting version for A and B, you can create and push a branch dedicated for their usage in a "parent" context. 确定A和B的有效起始版本后,您可以在“父”上下文中创建并推送专用于其使用的分支。
Then you make those submodule follow that branch , meaning any git submodule update --remote will checkout the latest SHA1 of that dedicated branch for submodules A and B . 然后你让那些子模块跟随那个分支 ,这意味着任何git submodule update --remote都会检查子模块AB专用分支的最新SHA1。

Just to make sure I understand your approach: 只是为了确保我理解你的方法:

Things I need to do to set up the library repository: 我需要做的事情来设置库存储库:

  1. Create the "parent" repository 创建“父”存储库
  2. Create a submodule for each library 为每个库创建一个子模块
  3. Dependencies must be relative, ie if D depends on B the path should look like ../../B/some folder 依赖关系必须是相对的,即如果D依赖于B,则路径应该看起来像../../B/some文件夹
  4. Each commit in the parent repository represents a valid combination of libraries 父存储库中的每个提交都代表一个有效的库组合

Things I need to do to include a chosen set of libraries into a new project: 我需要做的事情是将一组选定的库包含到一个新项目中:

  1. Create the "user" repository 创建“用户”存储库
  2. Create a branch in the required libraries respective repositories (eg A and B) like "for_user" and track this for the submodules in the "user" project. 在所需的库中创建一个分支各自的存储库(例如A和B),如“for_user”,并在“user”项目中跟踪子模块。
  3. Create a "from_user" branch in the "parent" repository that tracks changes from the used libraries ( is it possible to track repository branches on a per-branch base? ). 在“父”存储库中创建一个“from_user”分支,用于跟踪已使用库的更改( 是否可以在每个分支基础上跟踪存储库分支? )。
  4. Include the chosen set of libraries, eg A and B from the "for_user" branch. 包括所选的库集,例如“for_user”分支中的A和B.
  5. Changes made in A and/or B go to this branch and may be merged into the "parent" master branch if suitable and/or merged into other "from_..." branches from other projects using these libraries. 在A和/或B中进行的更改将转到此分支,并且可以合并到“父”主分支中(如果合适)和/或合并到使用这些库的其他项目的其他“from _...”分支中。 The "parent" project is used to create consistent sets of libraries. “父”项目用于创建一致的库集。

Effectively this means every "user" project that uses these libraries is represented by a branch "from_..." in the "parent" repository and a branch "for_..." in each used libraries repository. 实际上,这意味着使用这些库的每个“用户”项目都由“父”存储库中的“from _...”分支每个使用的库存储库中的“for _...”分支表示。

The setup should now look like this 现在应该看起来像这样

A
   branch "for_user"
   branch "master" (== for_parent)
   <other branches for each project using this library>

B,C,D
   <like A>


parent
   submodule A - tracks branch dependent on the current branch
   submodule B - tracks branch dependent on the current branch
   <other submodules>
   branch "master" (== from_parent)
   branch "from_user"
   <other branches for each project using one of the libraries>

user
   <own stuff>
   submodule A - tracks branch "for_user"
   submodule B - tracks branch "for_user"

Open questions: 开放式问题:

  • How do I automatically check out the correct set of libraries, eg A and B in the setup above? 如何在上面的设置中自动检出正确的库集,例如A和B? I could check out all available libraries, but that would somehow eliminate the need for separate sub-modules for each libraries 可以查看所有可用的库,但这将以某种方式消除每个库需要单独的子模块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Visual Studio 2010中设置Qt路径? - How do I set up Qt paths in Visual Studio 2010? 如何使 TODO 注释显示在 Visual Studio 2010 中 C++ 项目的任务列表中? - How do I make TODO comments show up in the task list for C++ projects in Visual Studio 2010? 如何将两个 Visual Studio 项目设置在同一个文件夹中? - How can I set two Visual Studio projects to be in the same folder? 如何在活动的Visual Studio配置中构建项目? - How do I get the projects to build in the active Visual Studio configuration? 尝试使用Visual Studio和git进行设置 - Trying to get set up with Visual Studio and git 如何查找 Visual Studio 项目中丢失的文件? - How do I find files that are missing from visual studio projects? 无法在Visual Studio中打开项目 - Not able to open projects in Visual studio 如何在Visual Studio中使用C#在解决方案中轻松获取文件夹内文件的路径? - How can I easily get the path of a file inside a folder in my solution in Visual Studio with C#? 如何在Visual Studio中轻松识别相同代码库的不同分支? - How do I easily identify different branches of the same codebase in Visual Studio? 如何在Visual Studio 2010中的C ++ googletest项目中设置代码覆盖率 - How do I set up code coverage in C++ googletest project in Visual Studio 2010
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM