Reputation: 11
I know I can how to open same folder in a new window.
dupl
But I'd like to also have different branch in each window.
But when I change branch in the first window, it also changes branch in the second window.
P.S. I don't need workspace, but I cannot have two opened windows with the same folder.
Upvotes: 1
Views: 3718
Reputation: 45749
Based on the question tags, it seems you're talking about opening multiple VS-Code windows, each viewing a different version of a file.
The git
part of the problem comes down to: how do you have both copies of the file available on disk at the same time?
Probably the best solution is to set up two worktrees. See the docs for git worktree (https://git-scm.com/docs/git-worktree). Then you open one window to each checked out worktree. This allows you to fully interact with each version on its own branch.
If your usage of one version or the other is read-only - i.e. you're referring to one version but working on the other - then it might work to keep your single worktree checked out to the version containing the version you're editing, but then you need to extract a copy of the other version of the specific file. For example
git checkout otherBranch -- path/to/file
mv path/to/file path/to/file.other
git checkout HEAD -- path/to/file
This might seem lighter-weight than setting up a whole second worktree, but you will want to remember to clean up the extra file when you're done with it.
Upvotes: 4
Reputation: 3923
Switching branches changes files in your working directory It’s important to note that when you switch branches in Git, files in your working directory will change. If you switch to an older branch, your working directory will be reverted to look like it did the last time you committed on that branch. If Git cannot do it cleanly, it will not let you switch at all. enter link description here
Upvotes: -1