I have installed two Windows servers with the latest versions of Cygwin and Git,
and I am trying to clone the git repository from S1 to S2.
I can successfully ssh from S2 to S1 using RSA keys, but when I do this :
git clone "ssh://root@S1/path/to/my/repo" it throws back this output:
Cloning into /cygdrive/c/program files/apache software foundation/apache2.2/… 2 [main] git 2004 C:/cygwin/lib/git-core/git.exe *** fatal error - cygheap base mismatch detected - 0x61242860/0x6123790. 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. --5 more errors like that one -- remote: Counting objects: 3275, done. remote: Compressing objects: 100% (3106/3106), done. fatal: write error: Broken pipe So I followed the suggested instructions, but no luck. Any suggestions?
116 Answers
I had the same problem.
I just restarted my PC and it worked again.
It doesn't help to find reason of problem but at least you can keep on to work.
2cygwin/git can be impacted by ASLR
In my case a Windows security feature called Address Space Layout Randomization (ASLR) had created this problem. ASLR should be off by default for programs that do not mark themselves compatible (more info).
I haven't checked if cygwin/git binaries had this flag in their headers, but I did have ASLR manually enabled for all apps as an extra security measure. As it had turned out, this made git commands stop working.
Solution
The solution was to exclude ASLR for git executables. Because there're quite many of them, I had to use PowerShell as administrator:
Get-Item -Path "C:\Program Files\Git\usr\bin\*.exe" | %{ Set-ProcessMitigation -Name $_.Name -Disable ForceRelocateImages } 2EDIT: I found the solution.
TL;DR: Go to the GitHub AppData folder and delete the PortableGit folder, and restart GitHub
- Close GitHub
- Navigate to the GitHub AppData folder:
C:\Users\[username]\AppData\Local\GitHub - Delete the folder that starts with
PortableGitand ends in a random string of letters and numbers - Restart GitHub. It will re-extract the dlls and the problem should be fixed!
(Original "answer") I tried a whole bunch of things, and I have no idea what actually worked in the end. I restarted GitHub, restarted my computer, uninstalled and reinstalled GitHub, uninstalled several other programs that I had recently installed but ended up not needing, deleted the GitHub folder in the AppData\Local directory, downloaded and installed cygwin, and possibly some other stuff I'm forgetting.
The last attempt was finding all the cygwin1.dll files in File Explorer and renaming them to cygwin1x.dll and then restarting my computer. After I did that, it worked again.
I'm hazarding a guess here, but I'm going to say that downloading and installing cygwin and then restarting my computer did the trick.
3For me, the cause was, git was not installed through cygwin, though the regular download from git-scm. Once I ran the cygwin setup, added git, it worked perfectly.
2You don't mention this in your problem statement, but I am presuming you are running on a 64 bit version of Windows. Cygwin has problems running on 64 bit Windows, especially with large programs. I believe this is due to memory management issues within the cygwin1.dll support library. It looks like it's making the unsupportable assumption that it will forever and always be mapped to the same address in every process, so it's okay for it to keep process specific things (like heap addresses) in system-wide global variables.
In my abundant free time, I've been trying to track down the problematic bits. In the meantime, you could try rebasing cygwin1.dll itself. Be warned, that's a great whackin' lot more complicated than it needs to be - even more complicated than rebasing all of everything else.
5Do you get this error with any other commands? With git --version?
Try rerunning the Cygwin setup.exe and reinstalling your cygwin1.dll (the package is "cygwin", under "Base") and your git package (package "git" under "Devel") and rebooting.
Solution below the wall of text (things that didn't work for me but maybe can help someone else?)
After updated Ruby + Devkit(MSYS2 toolchain) to 2.6.6-2 from 2.6.2-1 I got the cygheap error and couldn't continue working. I tried everything mentioned here. Probably put 6+ hrs into the problem. Nothing worked. I was ready to reinstall Windows.
- I've rebooted tens of times during the ordeal.
- I deleted Cygwin entirely, there is no
cygwin1.dllon the system.- I reinstalled Git, GithubDesktop, Ruby, and did a lot of messing around with MSYS2. The only outcome was learning MSYS can completely replace Cygwin - making cygwin unnecessary.
- For
Settings->Update & Security->Windows Security->App & browser control->Exploit protection settings->System settings, I have the following set to "Off by default"
- Mandatory ASLR (Force relocation of images not compiled with /DYNAMICBASE)
- Bottom-up ASLR (Randomize locations for virtual memory allocations)
- High-entropy ASLR
- As the sole owner and user of my computer with Powershell ISE running as admin, Windows has the gall to tell me
Requested registry access is not allowedif I try to runGet-ProcessMitigationorSet-ProcessMitigation. So that was a dead end.- I tried to rebaseall the msys64 dlls with (224MB of DLLs)
cd C:\msys64 && \usr\bin\dash /usr/bin/rebaseall -p -v
- On my 32GB RAM machine with 64GB of VirtualMem, it told me:
rebase: Too many DLLs for available address space: Cannot allocate memory- I spent a lot of time tweaking EnvironmentVars
System Path&User Pathand restarting.
- I learned the often repeated "User EnvVars override System EnvVars" is not true when it comes to the Path variable. System Path takes precedence because User Path is appended to System Path to make the
$PATHvar.
For this reason, the next bullet is a fix for some people, especially if bash fails to start- If you have WSL2 (Windows Subsystem for Linux) installed, odds are you're using
C:\Windows\System32\bash.exeinstead ofC:\Program Files\Git\usr\bin\bash.exe.
Win Bash doesn't play nice with MSYS, Cygwin, or Git-SCM.
- Make sure
C:\Program Files\Git\bin;comes beforeC:\Windows\system32;in the System Path Environment Variable. Since system32 is typically listed first,C:\Program Files\Git\bin;should be the new first entry.- Reviewed all the files bash loads on start checking for $Path manipulation and anything they may load
- In
%USERPROFILE%there's:\.bashrc,\.gitconfig,\.bash_profile,\.profile- In
C:\Program Files\Git\etcthere's:\profile.d,\profile.d\bash_profile.sh,\profile.d\env.sh,\bash.bashrc, and\profile- In
C:\Program Files\Git\usr\etcthere's more of the same above
Solution
The error message incorrectly cites cygwin1.dll as the issue. Git for Windows uses MSYS. The MSYS devs renamed the file to msys-2.0.dll and failed to update the error message.
- Find all the
msys-2.0.dll's on your machine and add the suffix.bkpto them. - Wherever you found them at, copy
"C:\Program Files\Git\usr\bin\msys-2.0.dll"to those locations.
Notes & Steps to Identify Issue:
- If you have WSL2, make sure
C:\Program Files\Git\bin;comes beforeC:\Windows\system32;in the System Path Environment Variable.- System32 is supposed to be the first System Path, but windows
bash.exeis in that folder - and it doesn't play nice with MSYS, Cygwin, or Git-SCM. Git Bash must be higher on the list to be selected over Win Bash.
- System32 is supposed to be the first System Path, but windows
- If you were to copy from
C:\msys64\usr\bin\msys-2.0.dllto all other locations, then you lose that nice additional text at the end that shows the branch you're on "(master)"
- Same goes if you decide to delete all the extra dlls and just add
C:\msys64\usr\binto your path, there must be a dependencies it looks for relative to the directory it normally resides.
- Same goes if you decide to delete all the extra dlls and just add
- To identify the
cygheapproblem, I checked the dlls being referenced at runtime with- Launch a new cmd.exe in a separate window for each of these steps. Must use exact paths to ensure the right things are loading.
- MSYS (cmd.exe window #1)
- run
set PATH="C:\msys64\usr\bin;" - run
"C:\msys64\usr\bin\bash.exe" - confirm
/c/msys64/usr/bin/ls.exe"works (should bcus loading ownmsys-2.0.dll) - The following will fail if they're referencing different
msys-2.0.dll's"/c/Program Files/Git/usr/bin/ls.exe"-> cygheap err"/c/cygwin64/bin/ls.exe""-> cygheap err
- run
- Cygwin (cmd.exe window #2)
- run
set PATH="C:\cygwin64\bin;" - run
"C:\cygwin64\bin\bash.exe"
Cygwin mangles the path. Checkecho $pathis correct.
if not run, runPath="/cygdrive/c/cygwin64/bin" - confirm
"/cygdrive/c/cygwin64/usr/bin/ls.exe"works - The following will fail if they're referencing different
msys-2.0.dll's"/cygdrive/c/msys64/usr/bin/ls.exe"-> cygheap err"/cygdrive/c/Program Files/Git/usr/bin/ls.exe"-> cygheap err
- run
- Git Bash (cmd.exe window #3)
- run
set PATH="C:\Program Files\Git\usr\bin\;" - run
"C:\Program Files\Git\usr\bin\bash.exe" - confirm
"/c/Program Files/Git/usr/bin/ls.exe"works - The following will fail if they're referencing different
msys-2.0.dll's"/c/msys64/usr/bin/ls.exe"-> cygheap err"/c/cygwin64/bin/ls.exe"-> cygheap err
- run
- Win Bash (cmd.exe window #4)
- Repeat the process for
"C:\Windows\System32\bash.exe". - On my machine it silently fails to even start. Which is one of the reasons I must have Git Bash loaded before system32 in the System Path
- Repeat the process for
- MSYS (cmd.exe window #1)
- With those consoles open, check the dlls being referenced
- Run
listdlls -r bash- Check the output for any dlls not like the others, then single it out
(in this casemsys-2.0.dll)
- Check the output for any dlls not like the others, then single it out
- Run
listdlls -r -v -d msys-2.0.dll - Check Base, Path, and Version info for discrepancies.
- Run
- Select the one you want to use everywhere (Git-Bash version best IMO) and remove the others.
- Launch a new cmd.exe in a separate window for each of these steps. Must use exact paths to ensure the right things are loading.
In my case the PATH in the Environment Variables was wrong. I moved the cygwin a bit earlier in the path (making sure it is set before git path). That way cygwin dll was in favor of git dll.
For example; The path of C:\Program Files\Git\usr\bin;C:\cygwin\bin;... Was changed to C:\cygwin\bin;C:\Program Filenter code herees\Git\usr\bin;...
Environment was Win7x86 and a reboot was required to that updated path is used.
For me this seemed to be just that there were two msys-2.0.dll in my path. One from Git For Windows, one from Msys2.
So the solution was just to rename:%APPDATA%\..\Local\Programs\Git\usr\bin\msys-2.0.dll (or %PROGRAMFILES%\Git\usr\bin\msys-2.0.dll) to msys-2.0.bak (or delete it).
I know this is an old thread, but as it is the first result on this issue, I would like to add my resolution in the hope it helps someone else.
First, run cygcheck PROGRAMM, in my case, I had an issue with tar.exe so I ran: cygcheck tar the cygcheck command shows what DLL's are used.
Everything looked correct in cygcheck, so I decided, based on the comments of Jim Schneider, to switch from the 64bit version of Cygwin to the 32bit version, that ultimately solved my problem.
For me the problem was existence of an older C:\cygwin64 folder. Renaming this folder was not enough. When I deleted this folder then the problem went away. I did not need to reboot after deleting the C:\cygwin64 folder either.
In my case rebooting the computer did not work.
I finally found that it was due to a conflict between an installation of Msys (Installed when I installed the command line git utilities). If your system path contains any directories with a version of Msys, delete such path entries and try again. It looks like cygwin tries to execute the executables from the Msys installation, and the .dll detects a missmatch.
I had the same kind of error when trying to push to a git repo from visual studio 2017 using a script starting with #!/bin/sh from
[repo folder]\.git\hooks\commit-msg Error message :
1 [main] sh (11460) c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\commonextensions\microsoft\teamfoundation\team explorer\Git\usr\bin\sh.exe: *** fatal error - cygheap base mismatch detected - 0x14DD408/0x12AD408.This problem is probably due to using incompatible versions of the cygwin DLL. Search for cygwin1.dll using the Windows Start->Find/Search facilityand 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 haveinstalled the cygwin distribution. Rebooting is also suggested if youare unable to find another cygwin DLL. I tried different solutions above without success
What I did to solve the issue is copying content from :
C:\Program Files\Git\usr\bin to
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\usr\bin The issue on my computer came from a version mismatch on sh.exe, and copying these files resolved the problem
I resolved this issue by temporarily disabling Windows Defender and trying again—see for details.
Context
All my older versions of Visual Studio (2017 and 2019) were working fine, but the newly installed Visual Studio 2022 had problems with Git in my Windows 10 computer.
Solutions that did NOT Work
- Rebooting Windows.
- Reinstalling Git through its official installer.
- Reinstalling/updating Cygwin64.
- Disabling force randomization for images (mandatory ASLR) in my system's Windows Defender Security Center.
- Excluding ASLR for git executables.
- Finding and deleting newer versions of
cygwin1.dll.
Actual Solution
- Find all
msys-2.0.dll(the method below is faster for finding files recursively than Windows Explorer, thank me later):
dir \msys-2.0.dll /s NOTE: As others pointed out, Git for Windows is actually using MSYS and not Cygwin. The MSYS team forgot to change the error messages when they imported and modified the Cygwin source code (source). Therefore, the actual file to search and delete is msys-2.0.dll, and NOT cygwin1.dll.
- Delete the occurrences of this file pertaining to the Visual Studio version which you are having trouble with. For instance, if you are having trouble with only Visual Studio 2022, then you only delete the
msys-2.0.dllfrom the paths beginning withC:\Program Files\Microsoft Visual Studio\2022\andC:\Program Files (x86)\Microsoft Visual Studio\2022\. - Delete the folder
C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git. - Open the Visual Studio Installer, -- you likely already have it on your computer since you have Visual Studio, otherwise, download it -- click on Modify the Visual Studio version which you are having trouble with, click on Individual components, and check the
Git for Windowsoption under Code tools.
NOTE: It doesn't matter if you already have Git installed in your machine; you still need to do this step.
- Restart your computer.
- Done.
I hope this helps you as it helped me.
2For me, it was the multiple versions of cygwin1.dll that messed up. I just made it by removing the link file of cygwin1.dll in this path C:\Users\someone\AppData\Roaming\Microsoft\Windows\Recent. The following were the error tips.
PS C:\WINDOWS\system32> gdb 0 [main] iconv (30916) C:\Program Files\Git\usr\bin\iconv.exe: *** fatal error - cygheap base mismatch detected - 0x800000000/0x210351408. 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. I used everything to find all cygwin1.dll files and the path above attracted my attention. I removed it and tested it again. Bingo.