简体   繁体   English

如何在 visual studio 中将项目添加到源代码管理(现有 GIT 远程仓库)?

[英]How to add a project to source control (existing GIT remote repo) in visual studio?

I have a solution (solution 1) that contains a project (project 1).我有一个包含项目(项目 1)的解决方案(解决方案 1)。 This project was added to source control and I do all git operations normally.该项目已添加到源代码管理中,我正常执行所有 git 操作。 I had another solution with another project (project 2) that had a different repo.我有另一个具有不同回购协议的项目(项目 2)的解决方案。

I want to merge these 2 solutions and put them under 1 solution only.我想合并这 2 个解决方案并将它们仅放在 1 个解决方案下。 So, I right clicked on my solution in solution 1 and added existing project (project 2) to it.因此,我在解决方案 1 中右键单击我的解决方案并将现有项目(项目 2)添加到其中。 My problem is that the git repo on azure devops can't see that I added this project to the solution so basically I can't commit or revert or do any git operation.我的问题是 azure devops 上的 git 回购看不到我将这个项目添加到解决方案中,所以基本上我无法提交或还原或执行任何 git 操作。 How can I fix that?我该如何解决? I need to add this project to source control but when I right click it, add to source control is not there.我需要将此项目添加到源代码管理,但是当我右键单击它时,添加到源代码管理不存在。

Thanks in advance提前致谢

Think of a local git repo as encompassing a parent folder.将本地 git 回购视为包含父文件夹。 It includes all the (tracked) files in that folder or sub-folders.它包括该文件夹或子文件夹中的所有(跟踪)文件。

In your Solution, there can be references that point to other folders, outside of that git repo.在您的解决方案中,可以有指向 git 存储库之外的其他文件夹的引用。 In fact, project/solution 2 already has a separate git repo, so that tells me it is in a different folder.事实上,项目/解决方案 2 已经有一个单独的 git 存储库,所以这告诉我它在不同的文件夹中。

You have a few ways of resolving this, but to start with, you mostly likely want to remove project 2 from solution 1 to start with.您有几种方法可以解决此问题,但首先,您很可能希望从解决方案 1 中删除项目 2。 Then decide how you want to add project 2 to solution 1.然后决定如何将项目 2 添加到解决方案 1。



Just leave them separate repos!只需将它们分开存储即可!

The easiest response is actually just to leave them separate repos.最简单的回应实际上只是让他们分开回购。 You can change them independently, and update them in their own repos - however, as you have noticed, there are likely some problems with this if you are using VS's native git interface - I think you would have to swap between solutions.您可以独立更改它们,并在它们自己的存储库中更新它们 - 但是,正如您所注意到的,如果您使用 VS 的本机 git 接口,这可能会出现一些问题 - 我认为您必须在解决方案之间进行交换。

The big downside of this is that git won't track which version of project 2 is being used at any given commit of solution 1 automatically.这样做的一大缺点是 git 不会自动跟踪在解决方案 1 的任何给定提交中正在使用项目 2 的哪个版本。 You would need a version explicitly indicated somewhere (I think it probably is somewhere in the solution config though?).您需要在某处明确指示一个版本(我认为它可能在解决方案配置中的某处?)。 I wouldn't rely on the solution configuration to track the underlying versioning for you - much better to have it all solidly tracked directly by git. From a version control system perspective, the other solutions are better.我不会依赖解决方案配置来为您跟踪底层版本控制——最好由 git 直接对其进行可靠跟踪。从版本控制系统的角度来看,其他解决方案更好。



Just copy the folder over直接把文件夹复制过来

The simplest solution that manages project 2 versioning is to just copy the project 2 folder from it's own folder / git repo into the folder / git repo for solution 1. First remove it from your solution, then copy it over, and readd project 2 from the new location.管理项目 2 版本控制的最简单解决方案是将项目 2 文件夹从它自己的文件夹 / git repo 复制到解决方案 1 的文件夹 / git repo 中。首先将其从解决方案中删除,然后复制过来,然后从中读取项目 2新位置。

After doing this, you can add it as a new project in solution 1, and all the links to it will be to this local copy.完成此操作后,您可以将其添加为解决方案 1 中的新项目,所有指向它的链接都将指向此本地副本。

However, the downside is that now solution 1/project 2 and the original project 2 in its separate repo are diverging.但是,缺点是现在解决方案 1/项目 2 和其单独回购中的原始项目 2 是不同的。 If project 2 is intended only for solution 1 at this point, that's probably fine.如果此时项目 2 仅用于解决方案 1,那可能没问题。



Make project 2 a submodule使项目 2 成为子模块

The slightly more complex solution is to make the repo for project 2 a submodule of the repo for solution 1. This adds it as a folder within your solution 1 folder hierarchy, so it looks just like the prior solution, but there is a little extra work to understand how to update the submodule.稍微复杂一点的解决方案是使项目 2 的回购成为解决方案 1 的回购的子模块。这会将它添加为解决方案 1 文件夹层次结构中的一个文件夹,所以它看起来就像之前的解决方案,但有一点额外努力了解如何更新子模块。

Basically, under this setup, the separate git repo is added with a reference to the correct commit in that repo to use at any given time.基本上,在此设置下,添加了单独的 git 回购协议,并引用了该回购协议中的正确提交,以便在任何给定时间使用。 You can update repo 2 completely separately, or can change it directly in the submodule, make new commits, etc., but they are separate repos, with git keeping track of which version of repo 2 (which commit) is being used at all times, so the version control is automatic.您可以完全单独更新 repo 2,或者可以直接在子模块中更改它,进行新的提交等,但它们是单独的 repos,git 始终跟踪正在使用哪个版本的 repo 2(哪个提交) ,所以版本控制是自动的。

Last time I used Visual Studio, I do not believe it's native git interface had support for sub-modules.上次我使用 Visual Studio 时,我不相信它的原生 git 接口支持子模块。 I'm not sure if it does now.我不确定现在是否如此。 You may need to learn how to manage them at the command line or with a separate visual GUI Git tool, like GitExtensions (on Windows only, for v3+).您可能需要了解如何在命令行或使用单独的可视化 GUI Git 工具(例如GitExtensions) (仅在 Windows 上,适用于 v3+)来管理它们。

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

相关问题 使用团队资源管理器中的 Git 存储库将现有项目添加到 Visual Studio 2017 解决方案中的源代码管理 - Add existing project to source control in Visual Studio 2017 solution using Git repo in Team Explorer 如何将现有的 Visual Studio 2019 项目添加到 git 存储库? - How can i add an existing visual studio 2019 project to a git repo? 如何在使用 Visual Studio 的项目中将 Git 存储库链接到现有 Git 存储库 - How do you link a Git Repo to an Existing Git Repo in a project using Visual Studio 如何将eclipse项目添加到现有的git仓库? - How to add eclipse project to existing git repo? 如何将现有的Visual Studio项目添加到空的git存储库 - How to add existing visual studio project to empty git repository Visual Studio 中的 Git - 添加现有项目? - Git in Visual Studio - add existing project? 将 Visual Studio 项目添加到现有的 git 存储库 - Add a visual studio project to an existing git repository 将现有Visual Studio 2013项目添加到Git源代码管理 - Adding Existing Visual Studio 2013 Projects to Git source control 如何将现有的本地源与NO本地git repo链接到远程git仓库 - How to link existing local source with NO local git repo to a remote git repo 如何使用Visual Studio 2017在VSTS上浏览远程Git存储库? - How to browse a remote Git repo on VSTS using Visual Studio 2017?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM