1

I am using git version 2.32.0.windows.2 and Visual Studio Code 1.58.2 (recently updated). Prior to about a week ago, If I was working on a feature branch, modified a file, and checked-out a different branch, I would get a message from git that I could not change branches without committing the modified file in the current branch. That is all fine.

Starting last week, when in the same scenario as above, I no longer get that warning, but I am allowed to change to the other branch and the message is:

Switched to branch 'development'
M       src/someFile.js
Your branch is up to date with 'origin/development'.

Even more disturbing is the fact that the file in the development branch does not get 'refreshed' with the version that is actually in the development branch, meaning the change that I made in the feature branch is also showing in the file explorer of VS Code.

Can anyone tell me why the 'normal' branch-switching behavior may have changed all of a sudden? Is it something to do with the updated git or VS Code apps or some setting that I inadvertently changed?

UPDATED: According to that duplicate question, I gather that sometimes git will force me to commit changes to my current branch before checking out another and sometimes it won't. Well, to date, I was never allowed to change to another branch no matter how small the change to the current branch is.

And, the answer to that question does not explain why when I switch to a different branch I should see the version of the file from that branch, not the one I just came from that had just been modified. Still no valid explanation for that.

tpdietz
  • 41
  • 4
  • 1
    That's what's supposed to happen. If the changes in your working area don't conflict, when you move between branches they stay in the working area. If they do, you can't move between branches. The changes aren't "on the branch" until you _commit_ them. – jonrsharpe Jul 19 '21 at 19:40
  • Found the perfect answer by @torek and linked the duplicate question. It should answer your question. If not, let us know. – knittl Jul 19 '21 at 19:49
  • From that question, I gather that sometimes git will force me to commit changes to my current branch before checking out another and sometimes it won't. Well, to date, I was never allowed to change to another branch no matter how small the change to the current branch is. And, that answer does not explain why when I switch to a different branch I should see the version of the file from that branch, not the one I just came from that had just been modified. Still no valid explanation for that. – tpdietz Jul 19 '21 at 20:04

1 Answers1

1

Local uncommitted changes are part of your working tree, they are not linked to any branch. They solely exist in your local files.

If Git wouldn't let you change in the past, that was only because a locally modified file was different between your HEAD commit and the being-switched-to branch. In that case Git needs to update the file contents' with the contents' stored in the branch's commit, which it cannot safely do when you have local changes.

Let me find the duplicate question, I'm sure there are several of them … (but all worded differently)

knittl
  • 246,190
  • 53
  • 318
  • 364