Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2015 Git error message "Cannot pull/switch because there are uncommitted changes"

I am having difficulty in doing a pull from origin. I keep getting:

"Cannot pull because there are uncommitted changes. Commit or undo your changes before pulling again. See the Output window for details."

This also applies to switching branches. I get a similar sort of message, but this does not always happen.

I am using Visual Studio 2015 Update 1 and Visual Studio Team Services Git. On my machine I have a local master branch, and development branches. Every time I switch to master and then I do a pull I get the error message. I have resorted to doing a stash and drop stash (command line) and sometimes I use TortoiseGit to do the pull and it works.

What is strange is even if I try to revert (on the uncommitted files) using TortoiseGit it shows that it was reverted successfully (I have already tried Visual Studio undo, nothing happens). Trying to pull again, it is still the same problem. The uncommitted files will be there and sometimes when I do a git status it says there is nothing to commit.

Just a note: This can happen even after switching from a branch onto master. In this case there is no way there can be uncommitted changes, because I would not have been able to switch in the first place.

I am still new to Git, but I would like to know if there is a better way of solving this as I would like to use one environment instead of using switching between different environments for each task; it's easier for me to just do everything from Visual Studio. I have already read up on:

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

UPDATE

It seems like this problem has to do with line endings.

By doing a git diff -R you can see that a line ending has been added, "^M", and it is different. Removing the * text=auto in gitattributes (then check for changes) and putting it back on again so that the gitattributes does not signal a change of itself that needs to be committed seems to help, there will not be any changes.

like image 639
kwiri Avatar asked Apr 15 '16 12:04

kwiri


4 Answers

For me I didn't have any uncommitted changes or any untracked files, and Visual Studio 2015 still presented the warning.

  1. Close the solution in Visual Studio, exit Visual Studio.
  2. Open Git Bash (or your favorite Git UI)
  3. Navigate to your repository (or open the repository with the Git UI)
  4. git pull (or perform pull on the Git UI)
  5. Merge happens (hopefully no conflicts, as in my case), vi opens (or the default merge resolution tool)
  6. :wq then press ENTER in vi (or calm handle the merge tool which popped up optionally) and hopefully this resolves it just like for me.
  7. Start Visual Studio 2015, open the project

I added a safer step-by-step by instructing closing and opening the solution and Visual Studio. This may be over cautious, and maybe a reload would be enough. This symptom could be a bug of the Visual Studio Git integration parts, and maybe it'll be resolved in the future.

like image 92
Csaba Toth Avatar answered Nov 06 '22 08:11

Csaba Toth


Type git status into a command line opened at that directory. If there is red and/or green text, you have changed some stuff and not added and committed. Either revert the files (by doing git checkout -- <file>), or add and commit (by doing git add --all then git commit -m "commit message"). You can then check out branches or whatever else you want to do.

like image 11
TechnicalTophat Avatar answered Nov 06 '22 07:11

TechnicalTophat


Try with these commands by going to the working directory of the project in the command prompt.

git add -A
git commit -m "your message"
git fetch origin master
git pull origin master
git push origin master //To push to the Git system
like image 9
Dhruv Avatar answered Nov 06 '22 06:11

Dhruv


This happens sometimes even with me. If you are using Visual Studio, there is an easy way to make your way clear.

For Visual Studio 2013 and above, follow the following instructions as this worked for me:

  • Go to menu ToolsNuGet Package ManagerPackage Manager Console.
  • Type git reset and hit Enter

That's it. Git will be reset and then you will be able to pull your request easily.

VS2015: Tools > Nuget Package Manager > Package manager console. Worked like a charm. Thanks.

like image 8
Yagnesh Khamar Avatar answered Nov 06 '22 07:11

Yagnesh Khamar