TFS/GIT in VS Cannot switch to master because ther

2019-02-01 05:56发布

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?

13条回答
2楼-- · 2019-02-01 06:03

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).
查看更多
Deceive 欺骗
3楼-- · 2019-02-01 06:04

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

查看更多
老娘就宠你
4楼-- · 2019-02-01 06:07

One thing that worked for me is :-
1) Right click on branch you want to checkout.
2) Click on the Reset option.
3) Click on the Delete Changes (--hard)
4) Right click on the branch and select checkout

查看更多
仙女界的扛把子
5楼-- · 2019-02-01 06:10

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.

查看更多
相关推荐>>
6楼-- · 2019-02-01 06:10

I've noticed a few times sln items are marked as changed but don't appear that way in Solution Explorer. What I have done as others suggested is in command prompt,

git status (this should show you culprit files)

then add the individual files. Or what I personally do is run:

git add -A 

which will add all changed files to view nicely in Team Explorer, where you can undo/delete as you want. Haven't had a problem with this approach.

查看更多
该账号已被封号
7楼-- · 2019-02-01 06:11

I ended up solving my issue by deleting my repo from within File Explorer and then from within Visual Studio selecting "undo all changes" when the deletions registered to be committed. Upon restoring the repo Visual Studio functioned as expected in tandem with git.

查看更多
登录 后发表回答