简体   繁体   中英

VS2013 Git — Cannot complete the operation because of existing changes to the following file

Using VS 2013, I have made a change to a file, successfully committed and pushed to the server. When I go to change to a different branch, I get the following error:

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

The output window of course shows the file I just committed and pushed. There are no files listed in the "Changes" area.

SourceTree shows no unstaged files and lets me change branches without a problem.

Any ideas?

It sounds weird, but last time I got this error message, all I had to do was physically remove the conflicted file and click on the "clear all" button of the output window. Until I cleared the error message, the bug continued.

In my case however I was doing a Pull, but the error message was the same (system claims to be pending commits but the change window is empty).

I tried the other two answers, no fix.

But here's what I tried that I believe made it reset itself in my case:

  • Find the offending file in Explorer
  • Rename it to remove its extension
  • Go back to VS, you'll find the Changes window shows the file with the rename action
  • Undo the rename change on that file

This should reset the state of the file and make it forget that there's a change on the file.
Now, you can simply switch or pull or do whatever was being blocked.

I had a similar issue, in my case i replaced a .jpg file with a new one with the same name but the new extension was ".JPG".

After changing the extension in the file shown in output window everything worked fine.

I came here in search of a solution to this same problem. Thanks to the hints given above, I discovered that the root project directory was missing a .gitignore file. After I copied one from another C# project into it, the problem went away. My Gitignore is pretty conventional.

This worked for me:

  1. View History of current branch
  2. Reset Hard to your last commit
  3. Checkout the other branch

Use these following commands :

$ git fetch --all
$ git reset --hard origin/master     
$ git checkout master
$ git pull origin master

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM