Sublime Forum

Not rewriting deleted files

#1

When switching git branches, several open files may be “deleted” from the working directory (because they’re not in the other branch). Next time Sublime saves, it’ll rewrite those files, which causes git to complain about overwriting them when switching back to the original branch.

This must be a fairly common problem given the popularity of git and I’m wondering if there are standard answers. From searching around, I didn’t find an obvious setting or plugin—although search results are overwhelmed with people trying to recover deleted files so it’s hard to tell.

1 Like

#2

surely if you tell ST to save a file, this would kinda be the expected behavior? or you mean it saves without you asking it to somehow?

0 Likes

#3

or you mean it saves without you asking it to somehow?

I’m absolutely asking it to save: either explicitly or by starting a build. None the less, rewriting files that have been deleted on disk is problematic when git is managing the working directory, although entirely sensible behaviour by Sublime. Given the dominance of git, I’m just assuming that others have had the problem and thus there’s probably a better answer than crafting one of my own.

0 Likes

#4

a plugin that closes files that no longer exist on disk which are part of project in a git repo? maybe something already exists like this, not sure

0 Likes

#5

A plugin that did something like that would be pretty easy to come up with, I think.

It should also be possible to catch the save command in an event listener and determine if it’s about to resurrect a deleted file and either block the save or redirect to a command that asks you for confirmation first, I would think.

I’m not sure if either of those already exist though. Generally when I work with Git and I’m moving between commits or branches, I tend to make sure that everything is saved and up to date before I execute any commands. So if a tab appears unsaved, I know it’s because that file is now considered deleted.

1 Like