0

I've encountered some unexpected behavior in Visual Studio Enterprise 2017 in a .NET Web API project. When I'm in a branch (not master), and I add some new files like a controller and a model, maybe exclude a file or two from project, etc. If I switch back to master, or to any other branch, these same files are added and/or excluded in this branch as well.

I thought the purpose of branches was to keep changes like this isolated? Perhaps changes in the file tree have always populated across branches and I just never noticed until now?

Is this behavior in Visual Studio expected?

Kyle Vassella
  • 2,296
  • 10
  • 32
  • 62
  • 1
    I don't use Visual Studio, but if you're not _committing_ those files this is expected behaviour in Git. Uncommitted changes don't belong to _any_ branch. – ChrisGPT was on strike Sep 25 '18 at 17:35
  • 1
    See https://stackoverflow.com/q/6286539/354577 and https://stackoverflow.com/q/5531362/354577, for example. – ChrisGPT was on strike Sep 25 '18 at 17:36
  • Possible duplicate of [Modified files in a git branch are spilling over into another branch](https://stackoverflow.com/questions/246275/modified-files-in-a-git-branch-are-spilling-over-into-another-branch) – phd Sep 25 '18 at 18:01
  • You are correct, Chris - not committing the changes to that branch was my problem. Much appreciated. – Kyle Vassella Sep 27 '18 at 16:21

1 Answers1

1

I've seen this same behavior in Visual Studio Code when adding files to the filesystem, but not when removing them. It may be different for Visual Studio Enterprise but I think this is intended. If you add files to the filesystem they don't want to delete them when you switch between branches. I think the deleted files can be brought back in by pulling from the branch. However the added files will stay until you .gitignore them, commit/push them, or remove them.

Frenchy
  • 90
  • 1
  • 10