如何使用相同的Git项目和不同的分支打开2个Visual Studio实例 [英] How to open 2 Visual Studio instances, with same Git projects and different branches

查看:269
本文介绍了如何使用相同的Git项目和不同的分支打开2个Visual Studio实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要打开2个Visual Studio实例,将为我打开一个实例,以仅查看Project X/Branch 1的代码. 另一个将用于在Project X/Branch 2中进行编码. 如何做到这一点并且不放松提交操作中的更改?

I am needing to open 2 Visual Studio instances, one will be opened for me to just look the code of the Project X /Branch 1. Another, will be used to code in the Project X / Branch 2. How to do that and don't loose changes in commit operation?

推荐答案

这里的问题与Visual Studio无关,而与git的工作有关. 当您在git中签出一个分支时,它将把该分支放入您的工作树中(文件结构,无论您希望调用什么).

The issue here isn't to do with visual studio, but the working of git. When you check out a branch in git it places that branch into your working tree, (file structure, whatever you wish to call it).

使用git一次只能签出一个分支,但是请等待解决方案! 通过使用git worktree命令,您可以在不同目录中为同一存储库创建第二个工作树.然后,您可以在Visual Studio中打开该工作树,以检出两个不同的分支.

With git you can only have one branch checked out at a time, but wait there is a solution! By utilising the git worktree command you can create a second worktree for the same repository in a different directory. You can then open that work tree in visual studio to have two different branches checked out.

假设您拥有"C:\ projects \ the_project",并且想在"C:\ projects \ the_project_2"处创建一个新的工作树,打开git bash,导航至项目目录并运行git worktree add ../the_project_2 <branch>,其中您要在新工作树中检出的分支.

Say you have "C:\projects\the_project" and you want to make a new work tree at say "C:\projects\the_project_2", open git bash, navigate to the project's directory and run git worktree add ../the_project_2 <branch> where is the branch you want checked out in the new work tree.

这将创建一个新目录("C:\ projects \ the_project_2")并将其签出到其中,而无需重新克隆存储库.

This will create a new directory ("C:\projects\the_project_2") and checkout the branch into it, without having to re-clone the repository.

有关更多信息,请参见 git工作树文档.

For more information see the git worktree documentation.

注意:Visual Studio的早期版本不知道如何处理其他工作树,因此不会将它们识别为git存储库.

Note: Earlier versions of visual studio do not know how to treat additional work trees, and will not recognise them as git repositories.

这篇关于如何使用相同的Git项目和不同的分支打开2个Visual Studio实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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