Visual Studio 2015 Git 错误消息“无法拉取/切换,因为有未提交的更改" [英] Visual Studio 2015 Git error message "Cannot pull/switch because there are uncommitted changes"

查看:106
本文介绍了Visual Studio 2015 Git 错误消息“无法拉取/切换,因为有未提交的更改"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从 origin 拉取数据时遇到困难.我不断得到:

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.

我使用的是 Visual Studio 2015 Update 1 和 Visual Studio Team Services Git.在我的机器上,我有一个本地 master 分支和开发分支.每次我切换到 master 然后我拉我都会收到错误消息.我求助于做一个 stash 和 drop stash(命令行),有时我使用 TortoiseGit 来做拉,它的工作原理.

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.

奇怪的是,即使我尝试使用 TortoiseGit 恢复(在未提交的文件上),它也表明它已成功恢复(我已经尝试过 Visual Studio 撤消,没有任何反应).再次尝试拉,还是一样的问题.未提交的文件会在那里,有时当我执行 git status 时,它说没有什么可提交的.

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.

请注意:即使从分支切换到 master 后,也会发生这种情况.在这种情况下,不可能有未提交的更改,因为我一开始就无法切换.

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.

我对 Git 还是个新手,但我想知道是否有更好的方法来解决这个问题,因为我想使用一个环境,而不是为每个任务使用不同环境之间的切换;对我来说,从 Visual Studio 做所有事情都更容易.我已经阅读了:

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:

VS 中的 TFS/GIT 无法切换到 master,因为有未提交的更改

更新

这个问题似乎与行尾有关.

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

通过执行 git diff -R 你可以看到添加了一个行尾,^M",它是不同的.删除 gitattributes 中的 * text=auto (然后检查更改)并再次将其重新打开,以便 gitattributes 不会发出需要提交的自身更改信号似乎有帮助,不会有有任何变化.

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.

推荐答案

对我来说,我没有任何未提交的更改或任何未跟踪的文件,Visual Studio 2015 仍然显示警告.

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

  1. 在 Visual Studio 中关闭解决方案,退出 Visual Studio.
  2. 打开 Git Bash(或你最喜欢的 Git UI)
  3. 导航到您的存储库(或使用 Git UI 打开存储库)
  4. git pull(或在 Git UI 上执行 pull)
  5. 合并发生(希望没有冲突,就我而言),vi 打开(或默认合并解析工具)
  6. :wq 然后在 vi 中按 ENTER (或冷静处理可选弹出的合并工具),希望这能像对我来说.
  7. 启动 Visual Studio 2015,打开项目
  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

<小时>

我通过指示关闭和打开解决方案和 Visual Studio 添加了一个更安全的分步.这可能过于谨慎,也许重新加载就足够了.此症状可能是 Visual Studio Git 集成部分的错误,也许将来会解决.


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.

这篇关于Visual Studio 2015 Git 错误消息“无法拉取/切换,因为有未提交的更改"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆