无法拉取,因为使用 VS2015/Git 存在未提交的更改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35111573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:45:12  来源:igfitidea点击:

Cannot pull because there are uncommitted changes using VS2015/Git

gitvisual-studiovisual-studio-2015dev-null

提问by OmegaExtern

Imagine the following scenario:

想象以下场景:

Manager has created a team project and decided to use (latest) git as VCS for the project. Developer team will be working using (latest) VS2015 (Enterprise) IDE. Manager has created a new (origin) branch called "master" and then committed & pushed 2 files to that branch.

经理创建了一个团队项目,并决定使用(最新的)git 作为项目的 VCS。开发团队将使用(最新)VS2015(企业)IDE 工作。经理创建了一个名为“master”的新(原始)分支,然后将 2 个文件提交并推送到该分支。

Project file hierarchy:

项目文件层次结构:

  Project (Root) Folder
    | notes.txt
    \ readme.md

Developer team made of "Jym" and "Bennie" has pulled origin/master branch (and both of them are working on local/master branch). Jym has committed & pushed the first change to "notes.txt" file (directly to master branch). Bennie has created a new file called "todos.txt", and also was making some changes to "notes.txt" file. Now when Bennie tries to sync/pull changes (that were made earlier by Jym), the following message is displayed in Synchronization window:

由“Jym”和“Bennie”组成的开发团队已经拉取了 origin/master 分支(他们都在本地/master 分支上工作)。Jym 已提交并将第一个更改推送到“notes.txt”文件(直接到 master 分支)。Bennie 创建了一个名为“todos.txt”的新文件,并对“notes.txt”文件进行了一些更改。现在,当 Bennie 尝试同步/拉取更改(Jym 之前所做的更改)时,同步窗口中会显示以下消息:

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

无法拉取,因为有未提交的更改。在再次拉取之前提交或撤消您的更改。有关详细信息,请参阅输出窗口。

To make things a whole lot worse for the team, Bennie is also experiencing the exact same issue that was opened in late December last year. This means that Bennie is practically unable to run any git command (however, all features but "undo" seems to work fine with Visual Studio Git/TFS providers - which he have found really weird).
Also because of that, this question is not (possible) duplicate of another question.

为了让团队的事情变得更糟,Bennie 也遇到了与去年 12 月下旬出现的完全相同的问题。这意味着 Bennie 实际上无法运行任何 git 命令(但是,除了“撤消”之外的所有功能似乎都可以在 Visual Studio Git/TFS 提供程序中正常工作——他发现这真的很奇怪)。
也正因为如此,这个问题不是(可能)另一个问题的重复。

How to solve the issue (from scenario described above) that Bennie is experiencing (using only Visual Studio of course)?

如何解决 Bennie 遇到的问题(来自上述场景)(当然只使用 Visual Studio)?

If there are any more details I can provide, please just post a comment.

如果我可以提供更多详细信息,请发表评论。

EDIT 1(output from suggested answerfor solving "null" device):
Results from the first step: Isn't that a typo in that answer, shouldn't "nul" be "nil"?
See screenshot

编辑1(从输出建议答案解决“空”的设备):
从结果第一步:是不是在回答一个错字,不应该“NUL”是“无”?
看截图

Results from the second step(Device Manager): With View -> "Show hidden devices" option checked, there are no devices with small "warning" icon (unknown/unrecognized device) or "null" in any of devices' names.
Also, apparently "Non-Plug and Play Drivers" type is not even being listed (of course when View -> "Devices by type" is selected).

第二步的结果(设备管理器):选中“查看”->“显示隐藏设备”选项后,任何设备名称中都没有带有小“警告”图标(未知/无法识别的设备)或“空”的设备。
Also, apparently "Non-Plug and Play Drivers" type is not even being listed (of course when View -> "Devices by type" is selected).

Results from the third step: %SystemRoot%\system32\drivers\null.sysfile had existed and was deleted from the disk (copied and pasted in null.sys file from Windows 10).
More details: Once right-clicked any of those sys files, there is no "Install" nor "Uninstall" option in context menu, default action seems to be "Open with..." (which is bolded).

第三步的结果:%SystemRoot%\system32\drivers\null.sys文件已存在并从磁盘中删除(从 Windows 10 复制并粘贴到 null.sys 文件中)。
更多详细信息:右键单击这些 sys 文件中的任何一个后,上下文菜单中没有“安装”或“卸载”选项,默认操作似乎是“打开方式...”(粗体)。

Results from fourth step: Attempt to merge null.regfailed. Reassigned owner of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Rootregistry key, also set up appropriate permissions.
null.regfile was successfully merged into registry after updating registry key permissions.
Restarting a computer.
Waiting for the final answer ... Error still on show!
See screenshot

第四步的结果:尝试合并null.reg失败。重新分配HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root注册表项的所有者,同时设置适当的权限。更新注册表项权限后,
null.reg文件已成功合并到注册表中。
重新启动计算机。
等待最终答案......错误仍然显示!
看截图

EDIT 2(testing PATH environment variable):
See screenshotSame error still occurs (even after opening git-cmd.exe or git-bash.exe as administrator).

编辑 2(测试 PATH 环境变量):
看截图同样的错误仍然发生(即使在以管理员身份打开 git-cmd.exe 或 git-bash.exe 之后)。

EDIT 3(power options, not using "Allow the Computer to Enter Away Mode" setting):
Reference thread.
See screenshot

编辑 3(电源选项,不使用“允许计算机进入离开模式”设置):
参考线程
看截图

EDIT 4:
After Bennie has upgraded his machine from Windows 8.1 to 10, issue has been solved. We can now simply conclude that operating system was corrupted.

编辑 4
Bennie 将他的机器从 Windows 8.1 升级到 10 后,问题已解决。我们现在可以简单地得出结论,操作系统已损坏。

回答by VonC

Whenever a GUI (here a VS with Git integration) steps out of the nominal path (here a git push not immediately possible), revert to the git command line interface.

每当 GUI(这里是与 Git 集成的 VS)退出名义路径(这里 git push 不是立即可能的)时,恢复到 git 命令行界面。

In your case, Bernie needs to a a git pull --rebase.

在您的情况下,伯尼需要 aa git pull --rebase

Open a git bash, and do (as Bernie)

打开一个 git bash,然后执行(作为 Bernie)

cd /path/to/repo
git status # make sure everything is committed
git pull --rebase
git status # you see notes.txt as being in conflict
# edit notes.txt and resolve the conflict by removing merge markers
git add .
git rebase --continue

git push

Note, git pull --rebasemightcome soon to Got for Visual Studio (follow @gitforvs):

请注意,Got for Visual Studiogit pull --rebase可能很快就会出现(如下@gitforvs):

g4vs

g4vs

Nothing official yet though.

不过还没有什么官方消息。



Regarding "Couldn't open /dev/null (or dup failed)", see if "Getting errors when using GitHub for Windows" could help (issue with the null device).

关于“ Couldn't open /dev/null (or dup failed)”,看看“使用 GitHub for Windows 时出现错误”是否有帮助(空设备问题)。

IF the error persists though, as in git-for-windows/git issue 583, re-installing Windows remains the surest way to get out of this predicament.

如果错误仍然存​​在,如git-for-windows/git issue 583,重新安装 Windows 仍然是摆脱这种困境的最可靠方法。

As mentioned by the OP OmegaExternin Edit 4, upgrading from win8 to win10 was enough to restore the device and solve the issue.

正如OP OmegaExtern在 Edit 4 中提到的,从 win8 升级到 win10 足以恢复设备并解决问题。