Sublime Forum

Open files and switching git branches

#1

Hi,

I was just wondering if anybody else had the problem and what they were doing about it:

When working on a project I frequently switch git branches (for example to quickly inspect work of someone else, or to fix a bug) and when I do so, I tend to have files open that don’t exist in that other branch.

ST2 now shows those files as unsaved while on the other branch and every so often it happens that I accidentally save one of those files for which I then have to go back into the command line and rm it in order to be able to switch back again.

Is there a way to make ST2 save the open file configuration, then, when switching to another branch possibly restore previously open files (and close the other ones) and vice versa?

I was thinking of resorting to simply having 2 clones of my git repository but then I would have to create a new virtualhost and remember to use the right one when checking things. With one clone it works fine, just ST2 is a little annoying with regards to that.

Anyone having the same trouble? What are your solutions? Thanks!

0 Likes

#2

Hmm, that’s an interesting problem. I haven’t had that problem yet, but maybe I will take a shot at a plugin to solve that issue. Not 100% sure how it will work yet, but my thinking is leveraging “git diff --name-status <current_branch>…<branch_switching_to>” close and open the necessary files. I’m guessing you are leveraging the Git plugin for sublime, so assuming what I’m thinking works, I’m not quite sure how it will integrate.

Sorry though, no immediate solutions for you.

0 Likes

#3

Related discussion: BUG: Saved, Open file becomes Dirty/Unsaved with unmount

0 Likes

#4

The problem does not seem to be restricted to files that are not in the branch you switch to. See: Bug: changes persisting across git branches

0 Likes