36

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?

rwkiii
  • 5,716
  • 18
  • 65
  • 114
  • Can you provide a screenshot of Team Explorer's Changes page? Does upgrading to VS 2013 Update 4 help? – Edward Thomson Nov 12 '14 at 12:32
  • Updates always seem to cost downtime... I am running VS 2013.2 - was there an issue related to this problem? – rwkiii Nov 13 '14 at 05:37
  • There were significant updates in better handling incorrect configurations with EOL settings. – Edward Thomson Nov 13 '14 at 14:54
  • 2
    I am having the same issue and I am on VS 2003 Update 4. Here's a screenshot: http://i.imgur.com/KioiygN.png Notice that it's complaining about changes, but doesn't list any. I can't even perform a commit because there are no changes. When I use an external git client such as git or gitExtensions, both show no changes. There are no unsync'd commits and nothing waiting to be pulled from the server. This is a VS bug. – Kushan Dec 17 '14 at 08:09
  • The answer from javovo does not yet have many upvotes, but it is clearly the best solution. – DavB.cs May 09 '18 at 19:44

14 Answers14

53

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.

Kushan
  • 1,200
  • 12
  • 22
  • 2
    I have to concur. I was looking all over without luck. I am using VS 2013 and I was stuck on a build - could not merge back to master. I also wasn't seeing the output - so the tip about changing to, "Source Control - Git" was very useful. One note: After deleting the file from disk your file may not appear in Included Changes. Mine showed up in Excluded Changes. – Rich Ward Sep 29 '15 at 18:36
  • 2
    This didnt work for me ;( It was a fresh install of VS2013. Did a fresh clone from master and it did a project "convert" and added a log file. I think that threw it off track even though output was showing a random file? Anyway, I did a manul git checkout and that fixed it. I can now change freely without problems. – Piotr Kula Feb 25 '16 at 19:13
  • 1
    I was also thinking about doing this.... good one! After spending so much time to solve this I feel like it's time to get away from Gui tools for Git – Dhanuka777 Mar 11 '16 at 03:27
  • Worked for me with VS2015 Community Edition. Any ideas when this bug occurs? It is really annoying when this occurs for many files in different directories when doing FI (forward integration) and RI (reverse integration) .... missing the days when we used SVN (Subversion) or TFS Source control ... never had such issues with SVN and even TFS source control seems to be more stable .... This and other issues let me hating Git ... – hfrmobile Mar 14 '16 at 15:31
  • Basically works, found the right files in the Output window after changing the window's view, but I found the problematic files in the "Untracked files list". I right clicked them and pressed "Ignore...." This solved the problem. – Sentinel Mar 16 '16 at 15:21
  • 1
    @Sentinel I would suggest updating your .gitignore file to use the one listed on github: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore This tends to solve issues like what you've just described and is a good start for 99% of Visual Studio projects. – Kushan Mar 17 '16 at 11:05
  • Worked for me as well (visual studio claimed I had uncommitted changes when I never made any changes at all!) – Nadav Ofir Dec 28 '16 at 16:18
  • The problem with git not bothers me rather than VS 2015 won't showing the changed file in output window as the message says. This is defensively a bug in VS, Is it reported or where I can report this issue? Once I have wrote them, but no response. – mihkov Mar 24 '17 at 12:57
  • Thanks for this! Solution still relevant in 2020 using VS 2019. – Ray Hogan Oct 29 '20 at 17:57
31

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

Baron
  • 975
  • 8
  • 12
  • 5
    +1. I had no changed files (in fact I had only just cloned the repro) yet VS wouldn't let me switch because of this error. In the end I just ran the command `git checkout ` and this worked fine. Clearly a bug in the VS plugin. – David Masters Apr 28 '15 at 11:09
  • This seemed to do it for me, I had no commits also, I did a git checkout and it worked after that – Jay Jan 05 '16 at 13:00
  • Just running the chekcout manually fixed it for me. I did a fresh VS2013 install, Git Windows install. Cloned and it did a project convert, inserting a log file. It got stuck there, i couldnt change from master. I did a manual checkout and all the branches work now. Phew! +1 – Piotr Kula Feb 25 '16 at 19:14
  • I did issued a "git status" and it said my branch was up to date, nothing to commit, which should have been true. What's so strange is the next time I tried to merge it worked and I don't believe anything else changed (other than my "show output from" in my Output window) I checked the documentation and it doesn't appear git status changes anything so I'm not sure how to explain this sudden successful merge – PTansey Jul 20 '17 at 15:53
  • Open a command prompt, do 'git status' and in VS perform a stage of pending files – Patrick Peters Aug 18 '17 at 14:27
  • I had same situation in vs2013: was in my only branch off of master and had committed all and synched all and got the same error when I tried to switch to Master from the current branch. Git status showed nothing to commit. Did checkout of master in git and all was fine. Went back into VS Team Explorer and the branch was now master. Then did a checkout of the other branch (in git) and VS 2013 showed the branch correctly. All is now copacetic. Agree: big MS bug; criminal negligence to not fix it – RRRSR Jul 10 '18 at 19:39
4

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

ランス
  • 418
  • 2
  • 8
3

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.

javovo
  • 317
  • 2
  • 7
3

1: Open git bash

2: Point to your git repository

3: check you branch status by using command "git status"

if you have any re usability of your changes for other branch then use "git stash save", (this will save your changes locally,you may face some conflict error, you can ignore for now) if you see any un-merged file in git status result and you want to keep the changes use "git add <file path>"

4: once your local changes are saved use command "git reset --merge"

this will reset your local branch to the original checkout, now you are ready to switch the branch you may see the conflict files in visual studio Team Explorer>changes, if you don't want to keep that file changes right click and select undo changes or use "git add <file path >" to add this file with other saved files.

5: Now your git branch is ready for switch, type "git checkout <branch path>"

6: to pop saved changes use "git stash pop", this will merge the saved changes in you current branch.

Satendra Jindal
  • 1,048
  • 3
  • 10
  • 15
2

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).
Asser
  • 109
  • 1
  • 9
  • the branch I am working in is important and so I don't think I want to merge/pull any changes from the master branch. To be honest, I don't see how there could be any changes in the master branch since I performed a commit and sync before creating the new branch. This problem has been going on for weeks... Do you have a way of knowing which branch contains the uncommitted changes? Is it in my local GIT repository or on visualstudio.com? Are the uncommitted changes in the master branch (that I can't get to) or the new branch I have been working in? :S – rwkiii Nov 13 '14 at 05:34
  • Uncommited changes are always local and on the branch you are currently on. If Visual Studio is acting up and not showing pending changes my recommendation would be to install git from i.e. http://git-scm.com/downloads and then use the Git Gui tool to see any pending changes. – Asser Nov 13 '14 at 09:14
  • Hello from 2016. These days, it is not always possible to talk VS into undoing a change. Sometimes it gets into a state where you can click on "Undo changes" and "Yes, dammit, I do mean it. That's why I clicked the other button," as many times as you please, but to no effect. One workaround is to commit the (fictitious) changes, then revert the committal. In the obligatory description of the committal, type something like "Appease GIT." – Jive Dadson Dec 20 '16 at 02:27
1

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.

WiseGuy
  • 409
  • 1
  • 8
  • 19
1

We regularly run into this issue, because we have a particular file which must always be excluded from changes, but sometime gets changed.

What works for us when the error message appears is:

  1. In VS look in the Output window to see which file is causing the issue.
  2. In Git bash run git update-index --no-assume-unchanged TheNameOfTheFileCausingTheIssue
  3. In VS Undo Checkout on this file
  4. In VS change the branch in Manage Branches.

This may or may not work for your situation, but I have added it in case it puts someone in the right direction. Please be sure you understand the git command before running it!

Dib
  • 2,001
  • 2
  • 29
  • 45
1

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

rbansal
  • 1,184
  • 14
  • 21
1

you probably have some conflict, and you have to reslove

this is one way to do it:

if you are on windows

  1. go to your project folder and open with git bash
  2. enter git pull and you will see whats file make problem only several files

there will be message like this <<<<error: Your local changes to the following files would be overwritten by merge: src/UCG.Custodian.WebUI/Web.config Please commit your changes or stash them before you merge. Aborting Updating ddd76137..b7ba45fa>>>

  1. undo or commit that files in may case only one src/UCG.Custodian.WebUI/Web.config

  2. and git pull

0

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.

TheFastCat
  • 3,134
  • 4
  • 22
  • 32
  • That was quick and easy. Thanks. I'm pretty sure the problem started when I renamed a file. – Tigran Jul 07 '15 at 16:57
0

The problem is that sometimes after pull path to some files do not match their equivalent in repository database because comparison is case-sensetive.

For example, you could have "MyLibrary\ABC\Folder\MyFile.cs" in repository but "MyLibrary\Abc\Folder\MyFile.cs" on the disk. There will be no changes detected in "git status" but Visual Studio will block branch switch.

Deleting just MyFile.cs from disk in that case will not solve the problem - you'll need to delete ABC directory and then undo changes for Visual Studio to recreate folder structure with correct names.

Michael Logutov
  • 2,551
  • 4
  • 28
  • 32
0

I had this issue after changing a filename from starting with a lower case letter to an upper case letter after I'd already committed the file. I fixed it by changing the name of the file (I just added a '1' on the end) and then committing that change. I was then able to switch branches.

As mentioned above, I had to change the 'Show output from:' combo to 'Source Control - Git' in the Output window in order to see the name of the offending file, that then showed me that the file name VS/git was expecting wasn't capitalised, where as the name in the solution explorer/on the file system was capitalised.

tomRedox
  • 28,092
  • 24
  • 117
  • 154
-1

i faced same problem then i noticed the uncommitted changes are from different project. once i committed those changes, it allowed me branch change.

hasan.in
  • 559
  • 6
  • 16