2

My first time using git with VSCode I had the experience of the file changes showing up in the Source Control even without saving them although now that doesn't happen anymore unless I manually save the modified file and that's when it appears in the 'Changes'. I haven't changed any settings/configuration and I'm not sure if manually saving a file within the repo in VSCode might've had an effect because I remember doing that before pushing and closing the editor.

I'd like to expand on this issue by detailing the previous behavior of my VSCode. After cloning a remote repo, git would automatically detect changes in existing files even though they haven't been saved yet although when a new file is added (say a text file) it had to be manually saved first and from then on Source Control would detect any changes to that file without having to save it.

Julius
  • 41
  • 5
  • I don't use VS Code often enough to be confident in this, but I don't recall seeing changes show up before the file is saved, in *VS Code*. However, I have seen exactly what you describe in *Visual Studio*, where, if you edit the file inside of Visual Studio it immediately shows the file as changed with a `*` next to it. Obviously it's "cheating" when it does that, as you can't see the change outside of VS until you save it. Is it possible you actually saw it in Visual Studio and not VS Code? Or, maybe a certain extension in VS Code does it that you aren't using now? – TTT Oct 06 '21 at 14:22
  • I don't have Visual Studio installed on this computer and the only extensions I've installed for VSCode are Live Share and Live Server. I haven't recently installed/uninstalled any extensions when this issue occurred. – Julius Oct 06 '21 at 14:44
  • OK. How long ago was it that you saw unsaved changes appearing in Source Control? – TTT Oct 06 '21 at 16:13
  • I started using VSCode with git around last month and right from the start after cloning a repo the changes made in tracked files already appear in Source Control without having to save them. It's only now that it stopped showing up and the only things I remember doing was manually saving a tracked file before pushing. – Julius Oct 06 '21 at 16:38
  • After some fiddling I can't figure out how to make it show what you described (originally). But in "Explorer" there is a blue number indicating an unsaved file, and I do see Open editors, and the modified and unsaved one is marked, and there is an option to compared that with the saved version. – TTT Oct 06 '21 at 17:00
  • Side note: This doesn't answer your question, but there is an auto save feature which when enabled will actually perform the save for you and is configurable for different options (timer, when you lose focus, etc). Might be a decent alternative if you can't get the old behavior back. And btw, if you do figure it out on your own, feel free to post your own answer to the question. – TTT Oct 06 '21 at 17:19
  • Does this answer your question? [Why don't other programs see the changes I made to a file in VS Code until I save those changes?](https://stackoverflow.com/questions/76984829/why-dont-other-programs-see-the-changes-i-made-to-a-file-in-vs-code-until-i-sav) – starball Aug 26 '23 at 22:36

2 Answers2

2

It's the right behaviour of how VS Code works with Git though. You save the file, then the editor (VS Code) notices the changes of the file, and shows it to the Source Control tab. Maybe the case when you first use the VS Code, is when you create a new file, and VS Code will also notice it.

chaukhoa97
  • 35
  • 5
  • I am aware the file must be saved for git to recognize the change as I used git bash before I moved to VSCode since the UI made it easier. I'd gotten used to VSCode's behavior of detecting file changes without having to save them (except when new files are added and you have to manually save them for the first time). Perhaps you have an idea if it's possible to restore that behavior for VSC? – Julius Oct 06 '21 at 13:51
2

Managed to get the 'old behavior' back thanks to TTT. I set the File Auto Save settings to onFocusChange and it behaves similarly to how it used to although I'm not sure why it stopped doing the old behavior as the settings were untouched and Auto Save was off by default. Anyway, thanks again to TTT.

Julius
  • 41
  • 5