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?
相关问题
- How to know full paths to DLL's from .csproj f
- Importing NuGet references through a local project
- Visual Studio 2019 - error MSB8020: The build tool
- 'System.Threading.ThreadAbortException' in
- VS2017 RC - The following error occurred when tryi
相关文章
- 请教Git如何克隆本地库?
- How to show location of errors, references to memb
- How to track MongoDB requests from a console appli
- Visual Studio Hangs on Loading UI Library
- How to use Mercurial from Visual Studio 2010?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on 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).
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.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.This will create a new directory ("C:\projects\the_project_2") and checkout the branch into it, without having to re-clone the repository.
For more information see the git worktree documentation.
Note: Earlier versions of visual studio do not know how to treat additional work trees, and will not recognise them as git repositories.
If you need to open the code in Visul Studio it is necessary to checkout the branch. As you can't checkout two different branches in the same directory at the same time, you can't avoid to checkout each branch in a separate directory.
But you can set the remote of one directory to the other git directory, so that you can synchronize locally and don't Need to have any external.
Assume you want to have both branches as subdirectories of a root common directory ProjectX:
Update May 2019: As git woorktree is now working and supported by GUI based tooling, this is probably the solution to use today.