Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've setup a GIT repository for a VS 2013 solution on visualstudio.com. The repository worked great while I was becoming accustomed to using TFS (in GIT mode).

Then I decided to familiarize myself with Branches, so I created a branch off of the master. I've made quite a few changes in this branch. I've committed the changes over time and have performed a Sync to push my local commits to the visualstudio.com repository. This all works.

The problem I am having is that I somehow lost the ability of switching back to the master branch. I cannot merge my newly created branch into the master. Every time I try to do anything that involves the master I get the following error in VS:

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

The Output window never contains any 'details'...

What "uncommitted changes" does this message refer to? Since I cannot get into the master branch I have no way of committing any of its changes (nor am I sure that I want to?). And the current (only other) branch I am in has been committed and sync'ed.

I'm really just learning TFS, GIT and source control. How do I safely recover from this problem?

like image 1000
rwkiii Avatar asked Nov 12 '14 10:11

rwkiii


3 Answers

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.

like image 184
Kushan Avatar answered Nov 15 '22 23:11

Kushan


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

like image 44
Baron Avatar answered Nov 16 '22 00:11

Baron


Hi this did the trick for me...

Try using the command prompt Team Explorer > Unsynced commit > Actions > Open Command Prompt

Do a git checkout branchName

like image 4
ランス Avatar answered Nov 16 '22 00:11

ランス