Git Bash (mintty) 在 Windows 10 操作系统上非常慢

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42888024/
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-09 04:53:48  来源:igfitidea点击:

Git Bash (mintty) is extremely slow on Windows 10 OS

gitwindows-10git-bashmingw-w64mintty

提问by Rohan Bhatia

I installed Git on my Windows 10a couple of months ago. It worked fine for some time. But now, it's running so slow.

几个月前,我在Windows 10上安装了 Git 。它工作了一段时间。但现在,它运行得如此缓慢。

The git statuscommand takes 7 secondsto execute, and git stashtakes many minutesfor stashing (even if there is nothing to stash). Also, I would like to point out that git statusprints the result instantaneously, but I can not enter a new command for a few seconds as shown in the image below.

git status命令需要7 秒才能执行,并且git stash需要很多分钟来存储(即使没有什么可以存储)。另外,我想指出git status即时打印结果,但我无法输入新命令几秒钟,如下图所示。

The screen is stuck like this for 7 seconds

屏幕就这样卡了7秒

I have tried surfing the net for solutions to my problem like this, this, etc. but none of these have worked.

我曾尝试在网上冲浪以解决我的问题,例如thisthis等,但这些都没有奏效。

P.S.:I use Windows Defender antivirus, and it is NOTmaking my Bash slow. Also, cmdtakes more time to execute gitcommands while git bashtakes a longer time to execute any command.

PS:我使用 Windows Defender 防病毒软件,它不会使我的 Bash 变慢。此外,cmd需要更多时间来执行git命令,而git bash需要更长的时间来执行任何命令。



Update:I have switched to Ubuntu and therefore, I don't use Windows presently. So, there is no way I can check if any of the solutions work for me. I am accepting the answer provided by @pschild since it has the most number of upvotes and seems to have worked for many people.

更新:我已切换到 Ubuntu,因此,我目前不使用 Windows。因此,我无法检查任何解决方案是否适合我。我接受@pschild 提供的答案,因为它拥有最多的赞成票并且似乎对很多人都有效。

采纳答案by pschild

I recently ran into the exact same issue. After trying all the advice from this thread and a lot of other threads, I finally found a solution here, respectively in the linked issue here.

我最近遇到了完全相同的问题。从这个线程和许多其他线程尝试所有的意见后,我终于找到了一个解决方案在这里,分别在链接的问题在这里

Disabling AMD Radeon graphics driver in the Windows device managerand switching to integrated Intel HD graphics worked for me- for whatever reason.

无论出于何种原因,在 Windows 设备管理器中禁用 AMD Radeon 图形驱动程序并切换到集成的 Intel HD 显卡对我都有效。

Hope that helps!

希望有帮助!

In my case, I found sh.exeshell to be significantly faster than bash.exe. You can find sh.exe in git_install_dir/bin.

就我而言,我发现sh.exeshell 比 bash.exe 快得多。您可以在 git_install_dir/bin 中找到 sh.exe。

Hope this helps people having this issue while only having integrated Intel HD graphics!

希望这可以帮助人们在仅集成英特尔高清显卡的情况下遇到此问题!

回答by Paul Wintz

For me, the solution was to set the HOME variable to my user directory (per this answer). To do this (at least on Windows 7):

对我来说,解决方案是将 HOME 变量设置为我的用户目录(根据这个答案)。为此(至少在 Windows 7 上):

  1. Right-click on "Computer" in file explorer.
  2. Open Advanced System Settings.
  3. Open Environment Variables
  4. Under System Variables, click "New..."
  5. Enter "HOME" for the variable name and the path to your user directory for the value (for example "C:\Users\jdoe").
  1. 右键单击文件资源管理器中的“计算机”。
  2. 打开高级系统设置。
  3. 开放环境变量
  4. 在系统变量下,单击“新建...”
  5. 为变量名输入“HOME”,为值输入用户目录的路径(例如“C:\Users\jdoe”)。

See also the answers to this related question.

另请参阅此相关问题的答案。

回答by VonC

Try again with:

再试一次:

  • the latest Git for Windowsyou can find, like PortableGit-2.12.1-64-bit.7z.exe(unzip it anywhere you want, no setup)
  • then in a CMDsession, set your PATHwith:

    set G=c:\path\to\latest\git
    set PATH=%G%\bin;%G%\usr\bin;%G%\mingw64\bin
    set PATH=%PATH%;C:\windows\system32;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\
    
  • set your HOMEin that same CMDsession

    set HOME=%USERPROFILE%
    
  • Finally, type bash, and see if any Git operation is still slow.

  • 最新的Git的Windows,你可以找到,像PortableGit-2.12.1-64-bit.7z.exe(解压缩任何你想要的,没有设置)
  • 然后在CMD会话中,设置您PATH的:

    set G=c:\path\to\latest\git
    set PATH=%G%\bin;%G%\usr\bin;%G%\mingw64\bin
    set PATH=%PATH%;C:\windows\system32;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\
    
  • HOME在同一个CMD会话中设置您的

    set HOME=%USERPROFILE%
    
  • 最后,输入bash,看看是否有任何 Git 操作仍然很慢。

回答by VonC

In response to Lafexlos's bounty:

回应Lafexlos赏金

Disabling AMD Radeon driver solved my issue but I am really wondering on why part.
Would appreciate an answer which focuses on that.

禁用 AMD Radeon 驱动程序解决了我的问题,但我真的想知道为什么部分。
希望得到一个专注于此的答案。

As to why:

至于为什么:

Issue 1070reports.

发布 1070份报告。

Bringing up the Radeon settings GUI and clicking on something while waiting for the bash prompt immediately releases something and makes it appear - weird.

调出 Radeon 设置 GUI 并在等待 bash 提示时单击某些内容会立即释放某些内容并使其出现 - 很奇怪。

AMD was contacted but no response...

联系了AMD但没有回应...

This project reports:

项目报告

But all of the graphic (terminal) output has to be displayed via those drivers.
They (the drivers) get their hooks into all parts of the system with hidden interrupts and time outs and goodness knows what. Shudders..

但是所有图形(终端)输出都必须通过这些驱动程序显示。
他们(驱动程序)通过隐藏的中断和超时将他们的钩子连接到系统的所有部分,天知道是什么。不寒而栗。。

Issue 1129adds:

问题 1129添加:

Starting with Windows 7 (maybe Vista?) the console had the ability to display itself via DirectWrite, which is build on top of Direct3D, which is heavily dependent on driver implementations of DirectX API.

As a former NVIDIA employee who worked directly on nvd3dum, nvwgf2umxand nvapiI can tell you we were rather skeptical of the wisdom of this decision.
Seems AMD should have been more skeptical, perhaps their driver quality would have been better.

从 Windows 7(也许是 Vista?)开始,控制台能够通过 DirectWrite 显示自己,它构建在 Direct3D 之上,它严重依赖于 DirectX API 的驱动程序实现。

作为一名前员工NVIDIA谁工作直接nvd3dumnvwgf2umx而且nvapi我可以告诉你,我们是相当怀疑这个决定的智慧。
看来 AMD 应该更加怀疑,也许他们的驱动程序质量会更好。

回答by rakwaht

I had the same problem once and what I found is that the issue for me was with __git_ps1, basically a variable that includes status informationlike branch name, detached head state, in the git dir, in a bare repo, in the middle of cherry picking or rebasing or merging.

我曾经遇到过同样的问题,我发现我的问题在于 __git_ps1,基本上是一个变量,其中包括状态信息,例如分支名称、分离的头状态、在 git 目录中、在裸仓库中、在采摘樱桃的中间或变基或合并。

In order to speed up your git bash, go to $GitHome\etc\profile and comment out the if-then where __git_ps1 isadded to PS1.

为了加速你的 git bash,转到 $GitHome\etc\profile 并注释掉__git_ps1 is添加到 PS1的 if-then where 。

Anyway the information that you are commenting out are quite useful, expecially if you are at the beginning with GIT. Here is a faster version, found on the internet and used by me quite succesfully on my system:

无论如何,您注释掉的信息非常有用,特别是如果您刚开始使用 GIT。这是一个更快的版本,在互联网上找到并被我在我的系统上成功使用:

fast_git_ps1 ()                                                                              
{                                                                                            
    printf -- "$(git branch 2>/dev/null | grep -e '\* ' | sed 's/^..\(.*\)/ {} /')"    
}                                                                                            

PS1='\[3]0;$MSYSTEM:\w##代码##7                                                                
3[32m\]\u@\h \[3[33m\w$(fast_git_ps1)3[0m\]                                         
$ '     

回答by Pramod C V

I had same issue on Windows 7 and Window 10, while using the git bash, any command that I run would take considerable time to execute. Finally after many of head breaking trials, found that issue was due to not running my git bash exe as administrator,

我在 Windows 7 和 Window 10 上遇到了同样的问题,在使用 git bash 时,我运行的任何命令都需要相当长的时间来执行。最后经过多次令人头疼的试验,发现问题是由于没有以管理员身份运行我的 git bash exe ,

Steps

脚步

  1. Right click on git bash exe.
  2. click on 'run as administrator'
  3. type in commands like cd /c/
  1. 右键单击 git bash exe。
  2. 点击“以管理员身份运行”
  3. 输入诸如 cd /c/ 之类的命令

hope this helps!!!!

希望这可以帮助!!!!

回答by Philip Rego

Is your PATH full of junk? Simple commands were taking 20 seconds or more for me sometimes until I removed unnecessary things from my PATH.

您的 PATH 是否充满垃圾?简单的命令有时对我来说需要 20 秒或更长时间,直到我从 PATH 中删除了不必要的东西。

Windows: echo %PATH%

Windows:回显 %PATH%

Search "edit environment variables" to change.

搜索“编辑环境变量”进行更改。

Other: echo $PATH

其他:echo $PATH

回答by mark

Adding process exclusion for bash.exe, cmd.exe and conhost.exe in Windows Defender Exclusions list apparently solved the issue for me on Windows 10 64bit.

在 Windows Defender 排除列表中为 bash.exe、cmd.exe 和 conhost.exe 添加进程排除显然解决了我在 Windows 10 64 位上的问题。

回答by csharpfolk

I have a similar problem but only when I ran git bashas a normal user, when I started git bashas an Administrator all commands ran really fast.

我有一个类似的问题,但只有当我git bash以普通用户身份运行时,当我git bash以管理员身份开始时,所有命令都运行得非常快。

In my case it turned out that the problem was caused by F-Secure antivirus. I added directory containing git.exeto the list of excluded directories (excluded from scanning) and it solved this problem for me.

就我而言,结果证明问题是由 F-Secure 防病毒软件引起的。我添加了包含git.exe排除目录列表的目录(从扫描中排除),它为我解决了这个问题。

How to exclude directory: https://community.f-secure.com/t5/Business/Excluding-objects-from-Real-Time/ta-p/66013

如何排除目录:https: //community.f-secure.com/t5/Business/Exducing-objects-from-Real-Time/ta-p/66013

回答by Kostiantyn Kolesnichenko

Tried everything above that made any sense to me, did not help.

尝试了以上对我有意义的所有内容,但没有帮助。

Finally I seem to have fixed the issue. Turned out, Git Credentials Manager for Windows tried to contact my domain controller (that is out of reach since I'm out of the office), and that caused a great delay (30+ seconds) each time I wanted to e.g. git checkout.

最后我似乎已经解决了这个问题。事实证明,Windows 版 Git 凭据管理器试图联系我的域控制器(由于我不在办公室,因此无法联系),这导致每次我想联系时的严重延迟(30 秒以上)git checkout

To fix this, just had to disable the Credentials Manager completely, now everything's reasonably fast. This is how to disable it: How do I disable Git Credential Manager for Windows?

要解决此问题,只需完全禁用凭据管理器,现在一切都相当快。这是禁用它的方法:How do I disable Git Credential Manager for Windows?

Hope this helps the desperate ones, cheers!

希望这对绝望的人有所帮助,干杯!