在 Visual Studio 中使用 git 子模块的工作流 [英] Workflow for using git submodules in Visual Studio

查看:43
本文介绍了在 Visual Studio 中使用 git 子模块的工作流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些共享代码,我想在多个解决方案中共享.大多数示例使用命令行,但我想使用 Visual Studio 2013(和/或 TortoiseGit)来实现?

I have some shared code I want to share among a number of solutions. Most examples use the command line, but I want to do it using Visual Studio 2013 (and/or TortoiseGit)?

- SolutionShared
  - .git
  - Project1Shared
  - Project2Shared
- Solution1
  - .git
  - ProjectFoo
  - ProjectBar
  - [SolutionShared]
    - [Project1Shared]
    - [Project2Shared]
- Solution2
  - .git
  - ProjectBaz
  - ProjectQux
  - [SolutionShared]
    - [Project1Shared]
    - [Project2Shared]

我所做的是创建一个新的解决方案 SolutionShared,在那里添加我所有的共享代码,并将其添加到自己的 git 存储库中.然后我使用 TortoiseGit(因为我不知道怎么做 Visual Studio)将该共享存储库作为 git 子模块添加到 Solution1Solution2.

What I did was to create a new solution SolutionShared, add all my shared code there, and add it to its own git repo. I then used TortoiseGit (as I couldn't figure out how to do it Visual Studio) to add that shared repo as a git submodule to Solution1 and Solution2.

1.我在 Visual Studio 中做什么?
我的两个解决方案现在有一个 SolutionShared 目录.我是否只需在 Visual Studio 中添加它的两个子项目(Project1SharedProject2Shared)?

1. What do I do in Visual Studio?
My two solutions now have a SolutionShared directory. Do I simply add its two child projects (Project1Shared and Project2Shared) in Visual Studio?

2.如何从非共享项目中更改共享代码
如果我在非共享解决方案之一中并对子模块中的某些内容进行更改,我如何提交并将其推送回共享解决方案的存储库 (SolutionShared) 以便它可用于引用它的所有解决方案?

2. How do I make changes to the shared code from within the non-shared projects
If I'm in one of the non-shared solutions and make a change to something in the submodule, how do I commit and push it back to the shared solution's repo (SolutionShared) so that it's available to all solutions that reference it?

推荐答案

经过多次试验...

在VS中,将子模块中的共享项目添加到解决方案中.就版本控制而言,它们似乎位于父解决方案的外部".

In VS, add the shared projects from the submodule to the solution. They seem to live "outside" the parent solution as far as versioning.

如果您对子模块的项目进行编辑,则它们是本地的.它们需要提交并推送到源代码库,然后您需要在那里合并它们.如果您在源代码处进行更改,则需要手动将它们拉入解决方案的 git 子模块中.

If you make an edit to the submodule's projects, they are local. They need to be committed and pushed to the source repo, and then you need to merge them there. If you make changes at the source, you need to pull them manually into your solution's git submodule.

问题是 VS 不会为你做任何这些,所以你需要使用类似 TortoiseGit 或命令行的东西.

Problem is VS doesn't do any of this for you, so you need to use something like TortoiseGit or the command line.

这篇关于在 Visual Studio 中使用 git 子模块的工作流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆