TFS/GIT in VS Cannot switch to master because there are uncommitted changes TFS/GIT in VS Cannot switch to master because there are uncommitted changes git git

TFS/GIT in VS Cannot switch to master because there are uncommitted changes


Okay, I had the same issue myself as rwkiii - this is a bug in Visual studio and is not an easy one to fix. Here are the symptoms:

Visual Studio states that you cannot merge/switch braches/etc. because you have uncommitted changes - which is fine, except all your changes have been committed.

Cannot switch to master because there are uncommitted changes. Commit or undo your changes before you switch branches. See the Output window for details.

Here's a screenshot to be clearer.

If you look at the output window, it may appear empty but you have to change "Show output from" to "Source Control - Git". This will list the file that Visual Studio thinks has changes.

Make sure "Source Control - Git" is selected

Now, things that I tried that didn't fix it (so you don't have to):

  • Restarting Visual Studio
  • Restarting the machine
  • Switching Projects
  • Using external git tools (All of which said "no changes")
  • git reset
  • Making arbitrary changes to the file and committing that. Commits ok, VS still thinks there's more changes

In the end, I had to go and delete the file from the disk, then "undo" that change from the Team Explorer window:

Click "undo" to restore the file and your ability to switch branches

Not the most ideal solution, but it does seem to fix it.


I used the git command prompt to resolve the issue. I can't guarantee that it's the best way or the only way, but it worked for me in Visual Studio 2013.

Under Changes in the Team Explorer, choose Open Command Prompt.

In the command prompt type:

git status

It will list the files that are open for change.

Copy off those files (just in case), then you can then discard the changes in the working directory in the command prompt.

git checkout -- mysubdir\myfile.ext

Don't attempt to change branches in Visual Studio, it still won't work!

Instead at the command prompt switch to the branch in question.

git checkout branchname

When you go back to Visual Studio it will prompt you to reload the project. After that the branch will be updated correctly to the branch you chose from the command line.

hth


I resolved a similar issue without having to delete a file or make new changes.

After committing changes on BranchA, merging with Master and pushing via Git bash, the next time I opened the project in VS and looked at Team Explorer, it showed that there were changes on the Master branch. No changes showed up when checking status via Git bash, but 10 files were listed in VS Output. Diffs on all files showed no changes. I tried a commit amend at this point, but it wouldn't let me amend the previous commit (see more about this below, since ultimately this will fix my issue).

Tried to switch to BranchA in VS and got the message that I can't switch due to uncommitted changes. Switch to BranchA via Git bash, and status shows no changes. Refresh VS Team Explorer so it is now on BranchA, shows 14 file changes, even more than Master, but again, diffs on all files showed no changes.

While on BranchA in Team Explorer, I clicked on Actions->Amend Previous Commit. This time it let it happen and all the changes were cleared. It then showed a pending commit, but checking status on Git bash showed nothing pending, so going to Home in Team Explorer and coming back, cleared the pending commit message.

Switched to Master in Team Explorer, no more changes showing there either. All is well.