74

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?

Henke
  • 4,445
  • 3
  • 31
  • 44
John Zumbrum
  • 2,786
  • 8
  • 36
  • 60

16 Answers16

69

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.

Serdar D.
  • 3,055
  • 1
  • 30
  • 23
  • 1
    I tried the ASLR solution below but it didn't help. Restart did help. – RuudSieb May 13 '19 at 06:18
  • Sorry, Windows 10 + LaTeX Asymptote + Git Bash (in 2021-present) obliterate this solution. 0% success after 100 restarts (literally). – MATHS MOD Apr 04 '22 at 09:11
63

cygwin/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 }
White hawk
  • 1,468
  • 1
  • 15
  • 23
  • 4
    Or even better `Get-ChildItem -Path C:\msys64 -Recurse -Include *exe | %{ Set-ProcessMitigation -Name $_.Name -Disable ForceRelocateImages }` – ZJR Feb 26 '18 at 06:24
  • 4
    @ZJR `Set-ProcessMitigation : The term 'Set-ProcessMitigation' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.` – Prostak Jul 17 '18 at 17:39
24

EDIT: I found the solution.

TL;DR: Go to the GitHub AppData folder and delete the PortableGit folder, and restart GitHub

  1. Close GitHub
  2. Navigate to the GitHub AppData folder: C:\Users\[username]\AppData\Local\GitHub
  3. Delete the folder that starts with PortableGit and ends in a random string of letters and numbers
  4. 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.

shieldgenerator7
  • 1,507
  • 17
  • 22
11

For 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.

Geoff Lentsch
  • 1,054
  • 11
  • 17
10

You 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.

Jim Schneider
  • 121
  • 1
  • 5
  • 1
    Well, according to http://cygwin.com/ml/cygwin/2006-11/msg00580.html, this is likely due to using a reserved field in the STARTUPINFO structure. Since the STARTUPINFO structure starts with its length, it should be pretty straightforward to just use a larger-than-expected structure to hold the data that is currently in this reserved field. I'll try it and comment again with my results. – Jim Schneider Apr 20 '12 at 14:31
  • 1
    Sorry it took me so long to get back to this. Again, I need to make an assumption - in this case, that the server is Windows 7, 64 bits. The problem was solved with 64 bit Vista via a run-time check that works around it on that platform. However, the problem still exists on Windows 7, but the workaround checks for version equality, rather than greater than or equal. I'll comment again with a patch momentarily. You will need the cygwin1.dll sources and a compiler suite to build it yourself. You may also need to run rebaseall afterwards. – Jim Schneider Jul 31 '12 at 13:24
  • 1
    In the file wincap.cc in cygwin-${VERSION}/winsup/cygwin, there's a structure with the name wincap7 (starts at line 271 in the 1.5.17 version of the sources). You will need to change the needs_count_in_si_lpres2 field from "false" to "true". This field is to work around a bug in Windows Vista 64 that's still in Windows 7 64 bit. – Jim Schneider Jul 31 '12 at 14:30
  • I think I'm hitting this in Windows 10 under MSYS2 64 bit. The field in wincap10 is "false" according to https://github.com/Alexpux/Cygwin/blob/4de8754bac676fc/winsup/cygwin/wincap.cc#L78. The executable is 140MB. Do you know if your proposed fix is still necessary? – letmaik Jul 30 '18 at 23:24
  • This also happens if you've turned on Mandatory ASLR under Exploit Protection in Windows 10; it is meant to be off by default. – Nathan Castle Oct 25 '19 at 03:26
7

Do 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.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • git status and git --version work just fine. Also, I can ssh to the server through cygwin. It looks like the cygwin version of git is having the issue, which is different from the version I installed on the OS directly. I'm reticent to try rerunning setup, due to the fact that it took me like an hour/hour and half the first time to install all the files. Unless you're suggesting there's a way to just install the piece I need? – John Zumbrum Nov 12 '11 at 22:09
  • Yes, the Cygwin `setup.exe` GUI lets you select just a few packages to install, uninstall, or update. – Keith Thompson Nov 12 '11 at 23:14
  • tried it on the dev computer, no difference. Did it on the production server, but it has to restart, so I won't know until at least tomorrow morning on that. – John Zumbrum Nov 13 '11 at 00:08
  • 1
    A Google search for "cygheap base mismatch detected" (with the quotation marks) gets a lot of its. I haven't followed the links, but you might want to. – Keith Thompson Nov 13 '11 at 00:42
3

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.dll on 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 allowed if I try to run Get-ProcessMitigation or Set-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 Path and 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 $PATH var.
      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.exe instead of C:\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 before C:\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\etc there's: \profile.d, \profile.d\bash_profile.sh, \profile.d\env.sh, \bash.bashrc, and \profile
    • In C:\Program Files\Git\usr\etc there'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 .bkp to them.
  • Wherever you found them at, copy "C:\Program Files\Git\usr\bin\msys-2.0.dll" to those locations. VoidTools Everything screenshot of msys-2.0.dlls

Notes & Steps to Identify Issue:

  • If you have WSL2, make sure C:\Program Files\Git\bin; comes before C:\Windows\system32; in the System Path Environment Variable.
    • System32 is supposed to be the first System Path, but windows bash.exe is 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.
  • If you were to copy from C:\msys64\usr\bin\msys-2.0.dll to all other locations, then you lose that nice additional text at the end that shows the branch you're on "(master)" Shows what branch you're on
    • Same goes if you decide to delete all the extra dlls and just add C:\msys64\usr\bin to your path, there must be a dependencies it looks for relative to the directory it normally resides.
  • To identify the cygheap problem, I checked the dlls being referenced at runtime with https://learn.microsoft.com/en-us/sysinternals/downloads/listdlls
    • 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.
      1. 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 own msys-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
      2. Cygwin (cmd.exe window #2)
        • run set PATH="C:\cygwin64\bin;"
        • run "C:\cygwin64\bin\bash.exe"
          Cygwin mangles the path. Check echo $path is correct.
          if not run, run Path="/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
      3. 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
      4. 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
    • With those consoles open, check the dlls being referenced
    • Select the one you want to use everywhere (Git-Bash version best IMO) and remove the others.
Derek Ziemba
  • 2,467
  • 22
  • 22
  • I had the same cygheap base mismatch error but only within VS Code bash terminal when I ran make or any tasks. I was sure that somehow the cygwin bash had been altered, but instead found VSCode's settings for terminal.integrated.shell.windows had been changed to git-bash.exe from the Cygwin's bash.exe. – RichR Jun 01 '21 at 21:00
2

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.

posix99
  • 356
  • 3
  • 13
2

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).

T.Todua
  • 53,146
  • 19
  • 236
  • 237
Peter Frost
  • 351
  • 3
  • 6
1

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.

0

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.

Farrukh Najmi
  • 5,055
  • 3
  • 35
  • 54
0

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.

Jorge Torres
  • 1,426
  • 12
  • 21
0

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

Xavave
  • 645
  • 11
  • 15
0

I resolved this issue by temporarily disabling Windows Defender and trying again—see https://superuser.com/a/1047031/158243 for details.

Bink
  • 1,934
  • 1
  • 25
  • 41
0

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

  1. 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.

  1. 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.dll from the paths beginning with C:\Program Files\Microsoft Visual Studio\2022\ and C:\Program Files (x86)\Microsoft Visual Studio\2022\.
  2. Delete the folder C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git.
  3. 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 Windows option under Code tools.

NOTE: It doesn't matter if you already have Git installed in your machine; you still need to do this step.

  1. Restart your computer.
  2. Done.

I hope this helps you as it helped me.

Raphael Setin
  • 557
  • 5
  • 10
  • 1
    This almost worked for me, with the difference that I did NOT delete the msys-2.0.dll file from the ..Microsoft Visual Studio.. folder, just renamed it to something temporary. Then as step 7. Restore the msys-2.0.dll to their original location. – akrobet Jun 27 '22 at 10:48
  • I followed all and there was no msys-2.0.dll except for one. And still have this problem. The ASLR solution is not useful for me either. – mercury Jul 11 '22 at 02:12
0

For 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.

W.Perrin
  • 4,217
  • 32
  • 31