gitvisual-studiovisual-studio-2019

files not updated automatically in visual studio when external git branch change


I am using visual studio 2019 and smartGit, an external git manager.

When I create a new solution with a C# console app, and many branches, if I use smartGit to change of branch, VS detects it (I see the change in the blue bottom status bar in VS) but the file changes are not automatically displayed, to display it I have to click on the file window in VS.

Why is the point of detect branch changes automatically if the files are not automatically updated? It can only confuse the user making him assume the file has been changed though it has not (I mean in the VS editor).

So I wonder if there is not a way to force this refresh in VS. Google and VS parameters did not help me.


Solution

  • VS, as other textual editors, like NotePad++, by default cache a copy of the file instead of accessing directly the file you have opened1.

    This design is made intentionally so that even if you completely delete a file from disk (say with ctrl+canc), a copy is still available for you to recover.

    Or, you may have a file automatically modified/generated by a routine, and this feature helps you retain that same file you've edited for an hour or so to identify that data row you were looking for.

    Apparently, this was being discussed by the VS community late in 2018 and a patch was released.

    That being said, the file has changed on disk when switching branches, and an attempt to build the solution will use the updated file. When inspecting the file in the IDE, the file is reloaded instead, showing the user that is now different.


    1. unlike other IDEs, such as , which directly show the edit (and often conflict with external git managers)