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?


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.

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:

    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 -- mysubdirmyfile.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


    Uncommited changes means that you have modified one or more files which have already been added to git and those changes have not been "saved" in a commit or in your git stash.

    When you switch between branches you are not allowed to have uncommited changes (new files that have not been added to git are fine though) as changes in other branches might overwrite your uncommited changes.

    I'm unfamiliar with how Visual Studio integrates with git as I myself use PoshGit with Powershell

    The way to proceed is to:

  • Undo your changes
  • Commit your changes
  • Or stash your changes (see the Interrupted workflow section).
  • 链接地址: http://www.djcxy.com/p/27092.html

    上一篇: Shopify:变量可在谢谢页面?

    下一篇: VS中的TFS / GIT由于存在未提交的更改,因此无法切换到主站