我是 Git 版本控制的新手。我只希望每个项目都有自己的存储库。
我建立
文件夹结构如下。
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?
同样:使用子模块会将您的代码作为其内容的一部分放在主项目中。将其本地保存在文件夹中或将其作为子模块的一部分之间的区别在于,在子模块中,内容被管理(提交)到不同的独立存储库。
这是子模块的图示 - 另一个项目中的项目,其中每个项目都是一个独立的项目。
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/