[英]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或任何版本控制系统。
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 add
” D
, C
, B
和A
的子模块:
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 . 而且,正如我在“ 子模块的真实性质 ”中所解释的那样,您可以在
A
, B
, C
或D
进行任何修改,并推送到各自的上游回购 。
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,添加并提交表示依赖回购A
, B
, C
和D
的新状态的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
. 这是一个组件的方法 ,其具有解决任何重叠依赖性的优势在于:如果
B
和C
需要不同版本的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
都会检查子模块A
和B
专用分支的最新SHA1。
Just to make sure I understand your approach: 只是为了确保我理解你的方法:
Things I need to do to set up the library repository: 我需要做的事情来设置库存储库:
Things I need to do to include a chosen set of libraries into a new project: 我需要做的事情是将一组选定的库包含到一个新项目中:
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: 开放式问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.