在 Windows 10 上使用 git 时,如何修复错误“致命错误 - 检测到 cygheap 基不匹配”?

在 Windows 10 上使用 git 时,如何修复错误“致命错误 - 检测到 cygheap 基不匹配”?

在Windows 10(1803)上使用git时,某些命令出现以下错误:

git submodule add https://github.com/..../......git ......
      3 [main] basename (13656) C:\.....\basename.exe: *** fatal error - cygheap base mismatch detected - 0x64313400/0x11E3400.
This problem is probably due to using incompatible versions of the cygwin DLL.
Search for cygwin1.dll using the Windows Start->Find/Search facility
and delete all but the most recent version.  The most recent version *should*
reside in x:\cygwin\bin, where 'x' is the drive on which you have
installed the cygwin distribution.  Rebooting is also suggested if you
are unable to find another cygwin DLL.

我该如何解决这个问题?

答案1

造成此错误的原因可能有多种。

例如,您确实可能有一个冲突的 DLL 版本。

但是,Windows 10 的最新版本内置了一组额外的保护功能,这些功能最初是 Microsoft EMET 的一部分。

最值得注意的是,ASLR(地址空间布局随机化) 安全功能与 Git for Windows 安装中包含的类 UNIX 可执行文件不兼容。

为了解决此问题,请打开“漏洞保护”设置,切换到“程序设置”选项卡并添加错误中列出的可执行文件名称(可能有很多)。

在给出的示例中,basename.exe如果您更加谨慎,则可以输入仅路径或完整路径。

对于每个可执行文件,关闭 ASLR 保护。

如需进一步参考,请参阅以下 GitHub 问题:

https://github.com/desktop/desktop/issues/3096

答案2

在 Windows 10 上默认启用强制 ALSR 后。

我需要对所有 git-bash 可执行文件禁用 ForceRelocateImages。为此,请创建一个小型 PowerShell 脚本或在 PowerShell 中直接输入以下代码。您需要以管理员身份运行 PowerShell。

Get-Item -Path "C:\Program Files\Git\usr\bin\*.exe" | %{ Set-ProcessMitigation -Name $_.Name -Disable ForceRelocateImages }
Get-Item -Path "C:\Program Files\Git\bin\*.exe" | %{ Set-ProcessMitigation -Name $_.Name -Disable ForceRelocateImages }
Get-Item -Path "C:\Program Files\Git\*.exe" | %{ Set-ProcessMitigation -Name $_.Name -Disable ForceRelocateImages }

此后,git-bash 可以正常工作。

答案3

对我来说,解决方案是删除不兼容的msys-2.0.dll。有关“cygwin”的错误消息是不正确的。

如果机器上有多个msys-2.0.dll文件,则可能会引起问题。删除所有文件,只保留 git 命令旁边的文件(c:\program files\git...)。

或者如果您需要多个版本,请使用 PATH 进行混乱,这样当您使用 git 命令时就不会找到 MSYS64 dll 版本。

答案4

  1. 重命名msysdll 可能会有帮助:https://stackoverflow.com/a/74463416/2377343

  2. 您可以尝试禁用 ASLR:https://stackoverflow.com/a/76296598/2377343

相关内容