1

I have done the following test on Visual Studio 2017:

1) Created new repo with master branch:

enter image description here

It just has a gitginore file:

enter image description here

2) Created Branch1 with file1:

enter image description here

enter image description here

3) Checkout master branch again, and opened 'Show folder view':

enter image description here

enter image description here

Why on earth am I seeing file1 in master branch?

enter image description here

Gadam
  • 2,674
  • 8
  • 37
  • 56
  • 5
    Did you commit File1 to Branch1? The behavior you are describing is expected if you did not commit this file to the branch. In its current state, File1 is an uncommitted change and will remain as such when you change branches assuming there is not a conflicting change on the branch you are changing to. – DenverDev Mar 12 '19 at 16:36
  • Thanks, looks like I might have missed committing it after all. I am transitioning from using command line git (for java) to Azure Devops 'git' Repos on Visual Studio and was frustrated for seeing that behavior. – Gadam Mar 13 '19 at 20:44

2 Answers2

2

If you move between branches but don't want to commit, just stash your changes.

It will clean up your environment, so that when you move to another branch nothing will be left behind. You will have a clean environment.

When you move back to the previous branch you can un-stash.

If you are familiar with TFS, a stash is such like a shelveset.

Take a look at https://git-scm.com/docs/git-stash

Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.

Saxophonist
  • 677
  • 9
  • 16
  • thanks for the clarification. I knew I could stash it, but was specifically concerned about what I described in the question. thanks. – Gadam Mar 13 '19 at 20:47
1

Both client side(Visual Studio) and server side(Azure DevOps) are standard implementations of Git.

Just as comment mentioned, this is the expired behavior in Git.

The created files(file1) are not put in the repository until you add and commit them.

If you switch back to your Branch1 branch and commit the file, then it won't appear on the master branch any more.

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62