简体   繁体   中英

Visual Studio Solution from multiple Git repositories

We have two different repositories on Git which need to come together to form the solution in Visual Studio.

Files under each project may be from the two different repositories. I need to make sure that when I make changes, it updates the changes in the correct repository (that is, the other repository should not perceive it at all) and also give me an option to add new files to a specific repository.

How can this be achieved, if can be done at all?

You can use submodules to realize it. Treat one repository as mainRepo and the other as subRepo.

  1. Based in the mainRepo and add the subRepo in it, use git submodule add subRepo's_URL
  2. Just make changes on files you want. You don't need to pay attention to which repository the files are from
  3. In the local mainRepo, use git commit –a –m 'input your comment' , and then modified files from mainRepo can be committed
  4. In the subRepo ( cd foldername ), you can also use git commit –a –m 'input your comment' , so modified files from mainRepo can be committed.

This may be different from want you thought, but it really saves you from which is the correct repository you want to update the changes in.

For more details about submodules, you can refer to here .

Visual 2022 finally has true multi-repo support. As of now, you have to enable it as a preview feature.

https://devblogs.microsoft.com/visualstudio/multi-repo-support-in-visual-studio/

It's now easy with the Project Manager extension. (At least this is true in Visual Studio Code, and I suspect it's true in VS, since VS is a super-set of VSC)

This is what I did in VS Code, it should be similar in Visual Studio

Assume you have a Git-type repo set up, and you have a separate and distinct top-level repository for each part of the project that must remain distinct.

In GitHub, (or similar) you create the two repositories needed and import files as necessary.

If the repositories/workspaces already exist on the local development machine, make sure that the repositories are fully up to date.

In Visual Studio code install the Project Manager extension.

On the development machine(s), you create a "top level" folder for the entire project as a whole, then open the folder in VSC.

Then save that folder as a "Project" At this point you should "clone" the repositories to folders inside the top-level project folders. You clone the repositories to a new location because moving repositories is a PAIN IN THE TUSH and causes nothing but trouble.

Save each cloned repository as a "workspace"

At this point, you have a "project" containing two workspaces.

Move any folders/files that don't get cloned to the new repository location as necessary.

Once you do all this, (it's actually easier than it sounds), you have access to both repositories as independent objects, commits go to the correct repository, yet you can work on them side-by-side, (sort of) if you wish. You do this by opening the second workspace into a new window.

Hopefully this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM