Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git: Preserve open files list when switching branches #35307

Open
fujitatakesh opened this issue Sep 28, 2017 · 111 comments
Open

Git: Preserve open files list when switching branches #35307

fujitatakesh opened this issue Sep 28, 2017 · 111 comments
Assignees
Labels
feature-request Request for new features or functionality scm General SCM compound issues
Milestone

Comments

@fujitatakesh
Copy link

I suggest for saving file opening status each git branches. I think the each branches need different files on the branches. If I changed branches and close and open files every time. Next time if I changed branch again, next process is closing opening files and opening files needed to edit. And next time...

@vscodebot vscodebot bot added the git GIT issues label Sep 28, 2017
@joaomoreno joaomoreno changed the title Save file opening status each git branches. Preserve open files list when switching branches Sep 28, 2017
@joaomoreno joaomoreno added the feature-request Request for new features or functionality label Sep 28, 2017
@joaomoreno joaomoreno added this to the Backlog milestone Sep 28, 2017
@joaomoreno joaomoreno removed their assignment Sep 28, 2017
@topaztee
Copy link

any updates on ths?

@mbonaci
Copy link

mbonaci commented Apr 10, 2018

Could this be done on the extension level?

@moriawan
Copy link

Is anyone working on this ?

@joaomoreno joaomoreno changed the title Preserve open files list when switching branches Git: Preserve open files list when switching branches Sep 18, 2018
@GargantulaKon
Copy link

I was wondering the same thing as I noticed that IntelliJ IDEA CE has that feature. I found it really useful. For now, I have to copy the relative path of every file to keep a list of opened files and then close the files. I then switch branches and then re-open files by searching for each of them.

I have also tried the workspaces feature to see if it saved the opened files, but alas it didn't.

@StephenGrable1
Copy link

This feature would be AMAZING

@jas-naz
Copy link

jas-naz commented Dec 1, 2018

I have been hoping for a feature/extension that would do this for months now. It would be great as I jump around a lot and have lots of files. I thought Workspaces was the answer but it doesn't seem to function that way.

@webworthydesign
Copy link

I recently switched from IntelliJ to VSCode and this has become a big problem and will likely cause me to need to switch back. It's a shame, I'd really like to have this feature added as I'm definitely enjoying VSCode but at my job, we switch branches far too often to keep opening/closing tabs so much. :(

@chinapalace
Copy link

This is the feature I want most to be added to VS code

@mymikemiller
Copy link
Contributor

This is something I'd really like too. I'd like to try my hand at implementing this feature. I have some questions for someone who knows the codebase better than I do.

  • Would this be better implemented as an extension, or in VSCode's codebase itself?
  • Where would be the proper place to store a map of branch names to open file paths such that they don't get checked into source control, but do persist across sessions? Where does VSCode store the list of open files that it restores when VSCode is closed and re-opened?
  • What's the best way to detect when a user switches their branch? Is there a way to do it without polling? This feature ought to work when the branch is switched outside of VSCode (e.g. in an external terminal)

@jack27121
Copy link

Any news? At all?

@romines
Copy link

romines commented Mar 15, 2019

The Restore Editors extension helps with this issue a lot.

@netzpixel
Copy link

@romines That doesnt help too much. It has to be automatic not manual.

@DanHitt
Copy link

DanHitt commented May 28, 2019

I would love to see this! Switching projects is very annoying.

@DanHitt
Copy link

DanHitt commented May 28, 2019

Any news?

@mbrammer
Copy link

mbrammer commented Jun 6, 2019

The only thing I am really missing in VS Code!

@kangzeroo
Copy link

This would be A+. In Atom there is a package called git-tabs.
https://atom.io/packages/git-tabs

@afalchi82
Copy link

afalchi82 commented Jul 10, 2019

Dear feature, we still miss you 🕯️

@bpartridge
Copy link

There may be a hard dependency on #15178 for this to be fully realized - I've done some research to try to unblock it but it'll definitely require some expansion of the extension API to be able to use internal services that describe the Groups of open editors. If this can be polled and modified reliably (and if we can open files into specific Groups), and Git can be polled as well, it could allow for some really interesting workflows!

@ilirhushi
Copy link

ilirhushi commented Sep 19, 2019

Check out this package: https://marketplace.visualstudio.com/items?itemName=eamodio.restore-editors

I found it very useful

@jcquinlan
Copy link

Just found https://github.com/gkotas/vscode-restore-git-branch-tabs as well. Haven't taken it for a full spin yet, but this seems to be the right idea.

@joaomoreno joaomoreno self-assigned this Oct 9, 2019
@joFolta
Copy link

joFolta commented Nov 22, 2019

Here's the link to the extension
https://marketplace.visualstudio.com/items?itemName=gkotas.restore-git-branch-tabs
Seems to work!

@JorgeSivil
Copy link

As a user from PHPStorm forced to use VSCode for remote development, this is a major pain

@dreit-p
Copy link

dreit-p commented Sep 25, 2023

I always remember this thread when I change my branches. It is essential functionality! In 5 days it will be 6 years of this issue. How will we celebrate it?

@adamc55
Copy link

adamc55 commented Nov 17, 2023

Definitely a feature that is sorely needed.

@rob-apella
Copy link

+1

@sakalosj
Copy link

any update?

@dreit-p
Copy link

dreit-p commented Nov 22, 2023

@starball5, you asked on StOv to avoid noisy comments like “+1/bump”. If I understand correctly, the bot here will close the issue as inactive if people will stop to make a noise here. The issue must live :)

@starball5
Copy link

starball5 commented Nov 22, 2023

@dreit-p If it's received enough thumbs up reactions to be added to the backlog (which it has), it does not get closed as inactive. Also, please please read https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions. This is not my personal advice. This is an official request from the maintainers of VS Code.

@paschalis-mpeis
Copy link

When working with different branches this would be indeed very useful.

@ds-clearago
Copy link

In #15824 this exact same problem is described, but that issue is closed because "This is now fixed.", as it says over there. I don't understand why though as this seems to be still open...

There does seem to be some movement in https://developercommunity.visualstudio.com/t/when-switching-branch-in-git-visual-studio-should/856415 though...

Do any of the extensions reliably work nowadays?

@mbonaci
Copy link

mbonaci commented Jan 3, 2024

"This is now fixed.", as it says over there

I really don't know what @joaomoreno meant when he wrote that in #15824 and I couldn't ask there, because he closed the issue.
Let's see whether he responds here.

@joaomoreno
Copy link
Member

I really don't know what @joaomoreno meant when he wrote that in #15824

Me neither. 😆

This issue is tracking this work.

@litera
Copy link

litera commented Jan 12, 2024

A different approach to this problem using Git worktrees

If you don't know what Git worktrees are, do check, because they're very useful. So until we actually see this VSCode feature implemented without resolving to addons, I started using Git worktrees which IMO is even better than this feature could ever be.

When I have to switch branch for some other work and not to loose whatever I've been doing in VSCode I now do this:

  1. I open a new Git worktree git worktree add ../[newFolderName] [branchName] naming the folder similarly to my primary repo folder name like [repoFolderName]-temp
  2. Open a new instance of VSCode
  3. Open the newly created worktree folder in VSCode

This way both VSCode windows keep their separate set of open editors not interfering with my work.
Why is using Git worktrees better? Because both folders are actually the same repository, so if you change something in one branch, the other branch is aware of it automatically. When switching between worktrees, you can even keep the other git index/staged untouched so everything (including VSCode workspace) will be completely untouched. That's why I'm saying that VSCode feature can never be as good as this, because you will still have to resolve to temporary commits or stashing before switching branches.

When I'm done working on the other more urgent branch I will simply close the related VSCode window and maybe keep the worktree for later use with some other branch (hence suffixing it with temp so can be used with any branch) or simply remove it using command git worktree remove ../[worktreeFolderName].

@starball5
Copy link

@litera yep. worktrees are the workaround I suggested using in my answer to the above linked SO question.

@zwarag
Copy link

zwarag commented Feb 6, 2024

This would be a very cool feature :)

@litera
Copy link

litera commented Feb 8, 2024

This would be a very cool feature :)

See this: #35307 (comment)

@litera
Copy link

litera commented Feb 8, 2024

@litera yep. worktrees are the workaround I suggested using in my answer to the above linked SO question.

IMO this workaround is even better than out of the box VSCode feature (if implemented). Why? Because without using worktrees, one would still need to use stashing or temporary commits (to be reset upon return to this branch), because that would be Git limitation when switching branches. Of course VSCode could do it for you, but I doubt that would be part of the feature, because one may have some files as changes and others staged (may be the same file actually) and that would be way to complicated to implement so that workspace branch restore would get you to the exact same state.

So after using worktrees approach I'm certain even if this VSCode feature ever comes out, I likely won't use it, because of the reasons stated above. I'm sold on the worktrees approach. And I'd urge everyone missing this VSCode feature to start using worktrees.

@russsaidwords
Copy link

@litera I appreciate that your opinion is that worktrees are a better way of going about this than the way that another IDE might. However, coming from another IDE to Code, it is absolutely jarring that this feature is missing from the built-in workflow. Those of us coming from JetBrains products (not by choice, mind you, but by requirement of our employers) to Code are absolutely aware of the limitations of the originally proposed solution - we've dealt with it in our other IDE regularly and it's not at all a surprise when we need to commit or stash changes before switching branches. The IDE makes this painless for the developer. Proposing that people delve into their terminals for something that could be built into the interface seems like, as you said, a workaround, and, I would add, a "hacky" one at that.

I will try using git worktrees in my workflow for now, and will wait (hopefully not another ~7 years) for this feature to be implemented in Code.

Let me be clear: I appreciate that you've stated your opinion. I appreciate all of the hard work that goes into making an editor such as Code. I appreciate that there are workarounds available. I am only actually upset that I can't use my IDE of choice at my place of employment and wish for all software, Code included, to improve over time. Given a proper settings flag to enable or disable this feature so that all parties could use it or not at their whim would, I believe, be a great win for all developers using Code.

@litera
Copy link

litera commented Feb 14, 2024

@russsaidwords: I will try using git worktrees in my workflow for now, and will wait (hopefully not another ~7 years) for this feature to be implemented in Code.

You do realise there are a few addons for VSCode that have certain capabilities within VSCode you're looking for? So that you don't have to use terminal.

But even regarding the terminal. You're correct. You do need to use the terminal or shell or whatever you please. But that's only actually needed when you create a worktree. If you decide to use it longtime, you can then do it all in VSCode. Open the directory of the worktree in VSCode, checkout branches, pull, push, commit... No need for the terminal any more after a worktree is created and running.

@russsaidwords
Copy link

@russsaidwords: I will try using git worktrees in my workflow for now, and will wait (hopefully not another ~7 years) for this feature to be implemented in Code.

You do realise there are a few addons for VSCode that have certain capabilities within VSCode you're looking for? So that you don't have to use terminal.

Indeed, I do realize that as I've read the discussion up to now. Why not have an official extension for performing such operations? Why not have an official extension that changes files based on the branch? This is precisely what JetBrains have done, and it works fabulously - I suggest you try their IDE for your language if you never have before.

But even regarding the terminal. You're correct. You do need to use the terminal or shell or whatever you please. But that's only actually needed when you create a worktree. If you decide to use it longtime, you can then do it all in VSCode. Open the directory of the worktree in VSCode, checkout branches, pull, push, commit... No need for the terminal any more after a worktree is created and running.

I'm not going to go into details here or talk about workflows with worktrees, except to say that in my limited experience with them and my major experience with a branch based file changing workflow (as the feature requested in this ticket), the second way is superior. This is my opinion. You have expressed yours. Your opinion that the workflow with worktrees is superior is that - your opinion. Others want the option to have a different way. That is all I will say more on this subject.

Thank you for your input.

@lszomoru
Copy link
Member

lszomoru commented Apr 12, 2024

Today's VS Code Insiders release (version details below) contains the first iteration of the ability to associate editor working sets (editors, layout) with a source control branch. You can enable this feature using scm.workingSets.enabled setting. You can also use the scm.workingSets.default (current, empty) setting to control the behaviour of switching to a branch that does not yet have a saved editor working set.

Please enable the feature, try it out, and let us know your feedback. Thank you!

Version: 1.89.0-insider (Universal)
Commit: 50a6f4f200c5a33f47997eb6a8966e50cf219e21
Date: 2024-04-12T05:52:00.589Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Darwin arm64 23.4.0

@lszomoru lszomoru added scm General SCM compound issues and removed git GIT issues labels Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality scm General SCM compound issues
Projects
None yet
Development

No branches or pull requests