Git Bash 在 Windows 7 x64 上非常慢

发布于 2024-10-08 08:32:08 字数 1149 浏览 5 评论 0原文

在开发一个小项目期间,我一直在 Windows 和 Ubuntu 上使用 Git,经常在两者之间来回切换。问题是 Git Bash 始终变慢。

当我说慢时,我的意思是运行 cd 需要 8-25 秒,运行 git 命令需要 5-20 秒,而 ls > 有时可能需要长达 30 秒。不用说,这并不有趣,更不用说没有生产力了。我知道 Git 在 Windows 上速度较慢,但​​这太荒谬了。

对我来说暂时有效的一个解决方案是禁用我的网络连接(如 这个答案),启动 Git Bash,然后重新连接。有时这样做后,它会继续快速运行几天,但性能最终总是会下降。我已经断断续续地浏览了 msysgit 讨论组、Stack Overflow、msysgit 问题列表等几个星期,但我一直无法找到有效的解决方案。

到目前为止,我已经尝试过:

  • 添加 Git &将项目文件夹添加到病毒扫描程序的排除列表
  • 完全禁用我的病毒扫描程序 (Kaspersky IS 2011)
  • 确保 Outlook 未运行 (Outlook 2007)
  • 关闭所有其他应用程序
  • 以管理员身份运行 Git Bash
  • 禁用网络连接,启动 Git Bash,并保持连接禁用
  • 禁用网络连接,启动 Git Bash,重新启用连接(仅偶尔有效)
  • 运行 git gc
  • 以及上述内容的组合

我确实读到有几个人成功禁用了 Bash 完成,但理想情况下我'我想保持活跃。 msysgit的版本是1.7.3.1-preview20101002&操作系统是 Windows 7 x64。可以预见的是,在 Linux 上运行同样的东西会快如闪电。我会专门使用 Linux,但我也需要在 Windows 中运行一些东西(某些应用程序、测试等)。

有人遇到过类似的问题吗?如果是这样,根本问题是什么以及解决方案是什么(如果有)?

这超出了 Git 存储库的范围,但仅供参考,我使用 Git 的存储库非常小:最多 4-50 个文件。

I've been using Git on both Windows and Ubuntu during the development of a small project, frequently flipping back and forth between the two. The issue is that Git Bash consistently becomes slow.

When I say slow, I mean that running cd takes anywhere from 8-25 seconds, running git commands take from 5-20 seconds, and ls can take up to 30 seconds sometimes. Needless to say, this is not fun, not to mention unproductive. I know Git is slower on Windows, but this is ridiculous.

The one solution which has worked--temporarily--for me has been to disable my network connection (as suggested in this answer), start Git Bash, and then reconnect. Sometimes it continues to run quickly for days after doing that, but the performance always degrades eventually. I've trawled through the msysgit discussion group, Stack Overflow, msysgit issue list, etc. on and off for weeks, but I haven't been able to turn up solutions which work.

So far, I've tried:

  • Adding Git & project folders to the virus scanner's exclusion list
  • Disabling my virus scanner completely (Kaspersky IS 2011)
  • Ensuring that Outlook is not running (Outlook 2007)
  • Shutting down all other applications
  • Running Git Bash as administrator
  • Disabling network connection, starting Git Bash, and keeping connection disabled
  • Disabling network connection, starting Git Bash, re-enabling connection (works only occasionally)
  • Running git gc
  • And combinations of the above

I did read that a couple of people had success disabling Bash completion, but ideally I'd like to keep that active. The version of msysgit is 1.7.3.1-preview20101002 & the OS is Windows 7 x64. Running the same things on Linux is, predictably, lightning fast. I would use Linux exclusively, but I need to run stuff in Windows, too (certain applications, testing, etc.).

Has anyone encountered a similar issue? If so, what was the underlying problem and what was the solution (if any)?

This extends beyond just the Git repositories, but just for reference, the repositories I've been using Git with have been pretty small: ~4-50 files maximum.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(25

谁对谁错谁最难过 2024-10-15 08:32:08

您可以通过运行三个命令来设置一些配置选项,从而显着加快 Windows 上的 Git 速度:

git config --global core.preloadindex true
git config --global core.fscache true
git config --global gc.auto 256

注意:

  • core.preloadindex 并行执行文件系统操作以隐藏延迟(更新:在 Git 2.1 中默认启用) )

  • core.fscache 修复 UAC 问题,以便您不需要以管理员身份运行 Git(更新:在 Windows 2.8 的 Git 中默认启用)

  • gc.auto 最大限度地减少 .git/ 中的文件数量

You can significantly speed up Git on Windows by running three commands to set some config options:

git config --global core.preloadindex true
git config --global core.fscache true
git config --global gc.auto 256

Notes:

  • core.preloadindex does filesystem operations in parallel to hide latency (update: enabled by default in Git 2.1)

  • core.fscache fixes UAC issues so you don't need to run Git as administrator (update: enabled by default in Git for Windows 2.8)

  • gc.auto minimizes the number of files in .git/

甜柠檬 2024-10-15 08:32:08

您的 Bash 提示符中是否显示了 Git 信息?如果是这样,也许您无意中在每个命令上做了太多的工作。为了测试这个理论,请尝试在 Bash 中进行以下临时更改:

export PS1='

Do you have Git information showing in your Bash prompt? If so, maybe you're inadvertently doing way too much work on every command. To test this theory try the following temporary change in Bash:

export PS1='

鹤仙姿 2024-10-15 08:32:08

我的 Windows 主目录位于网络上,我怀疑 Git Bash 命令首先查找那里。果然,当我查看 $PATH 时,它首先列出了 /h/bin,其中 /h 是 Windows 文件服务器上的共享,即使 /h/bin 不存在。
我编辑了 /etc/profile 并注释掉了将其放在 $PATH 中的导出命令:

#export PATH="$HOME/bin:$PATH"

这使我的命令运行得更快,可能是因为 Git Bash 不再查找通过网络获取可执行文件。我的 /etc/profilec:\Program Files (x86)\Git\etc\profile

My Windows home directory is on the network, and I suspected that Git Bash commands were looking there first. Sure enough, when I looked at $PATH, it listed /h/bin first, where /h is a share on a Windows file server, even though /h/bin doesn't exist.
I edited /etc/profile and commented out the export command that puts it first in $PATH:

#export PATH="$HOME/bin:$PATH"

This made my commands run much faster, probably because Git Bash is no longer looking across the network for the executables. My /etc/profile was c:\Program Files (x86)\Git\etc\profile.

人间☆小暴躁 2024-10-15 08:32:08

我发现网络驱动器是性能问题。 HOME 指向一个缓慢的网络共享。
我无法覆盖 HOMEDRIVE ,但从我所看到的来看,这不是问题。

右键设置环境变量
您的计算机桌面上 -->属性-->高级系统设置-->环境变量
添加到用户变量部分

HOME=%USERPROFILE%

I found the network drive was the performance problem. HOME was pointing to a slow network share.
I could not override HOMEDRIVE but that is not a problem from what I have seen.

Set the environment variable by right clicking
your computer on the desktop --> properties --> Advanced system settings --> Environment Variables
Add to User variables section

HOME=%USERPROFILE%
錯遇了你 2024-10-15 08:32:08

在 Chris Dolan 答案的扩展中,我使用了以下替代 PS1 设置。只需将代码片段添加到您的 ~/.profile(在 Windows 7 上:C:/Users/USERNAME/.profile)。

fast_git_ps1 ()
{
    printf -- "$(git branch 2>/dev/null | sed -ne '/^\* / s/^\* \(.*\)/ [\1] / p')"
}

PS1='\[\033]0;$MSYSTEM:\w\007
\033[32m\]\u@\h \[\033[33m\w$(fast_git_ps1)\033[0m\]
$ '

这保留了彩色 shell 和显示当前分支名称(如果在 Git 存储库中)的优点,但在我的机器上速度明显更快,从 ~0.75 秒到 0.1 秒。

这是基于这篇博文

In an extension to Chris Dolan's answer, I used the following alternative PS1 setting. Simply add the code fragment to your ~/.profile (on Windows 7: C:/Users/USERNAME/.profile).

fast_git_ps1 ()
{
    printf -- "$(git branch 2>/dev/null | sed -ne '/^\* / s/^\* \(.*\)/ [\1] / p')"
}

PS1='\[\033]0;$MSYSTEM:\w\007
\033[32m\]\u@\h \[\033[33m\w$(fast_git_ps1)\033[0m\]
$ '

This retains the benefit of a colored shell and display of the current branch name (if in a Git repository), but it is significantly faster on my machine, from ~0.75 s to 0.1 s.

This is based on this blog post.

风吹雨成花 2024-10-15 08:32:08

虽然您的问题可能是基于网络的,但我个人通过进行两项修改,将本地 git status 调用速度提高了十倍(7 秒以上降至 700 毫秒)。这是一个 700 MB 的存储库,包含 21,000 个文件和大量的大型二进制文件。

一是启用并行索引预加载。从命令提示符处:

git config core.preloadindex true

这将 时间 git status 从 7 秒更改为 2.5 秒。

更新!

以下不再是必要的。自 mysysgit 1.9.4 起,补丁已修复此问题
https://github.com/msysgit/git/commit/64d63240762df22e92b287b145d75a0d68a6 6988
但是,您必须通过键入
来启用修复
git config core.fscache true

我还禁用了 UAC 和“luafv”驱动程序(需要重新启动)。这会禁用 Windows Vista、7 和 8 中的驱动程序,该驱动程序会重定向尝试写入系统位置的程序,并将这些访问重定向到用户目录。

要查看有关这如何影响 Git 性能的讨论,请阅读此处:
https://code.google.com/p/msysgit/issues/ detail?id=320

要禁用此驱动程序,请在 regedit 中将 HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/luafv 中的“start”键更改为 4 以禁用该驱动程序。然后,将UAC设置为最低设置,“从不通知”。

如果禁用此驱动程序让您保持警惕(应该如此),则可以选择在与系统分区不同的驱动器(或分区)上运行。显然,该驱动程序仅在系统分区上的文件访问上运行。我有第二个硬盘,在 C 盘上进行此注册表修改后运行时看到的结果与在 D 盘上没有修改时看到的结果相同。

此更改将 time git status 从 2.5 秒减少到 0.7 秒。

您可能还想关注 https://github.com/msysgit/git/pull/94< /a> 和 https://github.com/git/git/commit/d637d1b9a8fb765a8542e69bd2e04b3e229f 663b 查看针对 Windows 中的速度问题正在进行哪些额外工作。

While your problem might be network-based, I've personally sped up my local git status calls tenfold (7+ seconds down to 700 ms) by doing two modifications. This is on a 700 MB repository with 21,000 files and excessive numbers of large binary files.

One is enabling parallel index preloads. From a command prompt:

git config core.preloadindex true

This changed time git status from 7 seconds to 2.5 seconds.

Update!

The following is no longer necessary. A patch has fixed this as of mysysgit 1.9.4
https://github.com/msysgit/git/commit/64d63240762df22e92b287b145d75a0d68a66988
However, you must enable the fix by typing
git config core.fscache true

I also disabled the UAC and the "luafv" driver (reboot required). This disables a driver in Windows Vista, 7 and 8 that redirects programs trying to write to system locations and instead redirects those accesses to a user directory.

To see a discussion on how this affects Git performance, read here:
https://code.google.com/p/msysgit/issues/detail?id=320

To disable this driver, in regedit, change the "start" key at HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/luafv to 4 to disable the driver. Then, put UAC to its lowest setting, "never notify".

If the disabling of this driver makes you wary (it should), an alternative is running on a drive (or partition) different than your system partition. Apparently the driver only runs on file access on the system partition. I have a second hard drive and see identical results when run with this registry modification on my C drive as I do without it on the D drive.

This change takes time git status from 2.5 seconds down to 0.7 seconds.

You also might want to follow https://github.com/msysgit/git/pull/94 and https://github.com/git/git/commit/d637d1b9a8fb765a8542e69bd2e04b3e229f663b to check out what additional work is underway for speed issues in Windows.

请叫√我孤独 2024-10-15 08:32:08

看来完全卸载 Git、重新启动(经典的 Windows 解决方法)并重新安装 Git 就是解决方法。我还清除了所有剩下的 bash 配置文件(它们是手动创建的)。一切又变得很快了。

如果由于某种原因无法(或不需要)重新安装,那么我肯定会尝试更改 Chris Dolan 的回答;它导致某些操作的显着加速。

It appears that completely uninstalling Git, restarting (the classic Windows cure), and reinstalling Git was the cure. I also wiped out all bash config files which were left over (they were manually created). Everything is fast again.

If for some reason reinstalling isn't possible (or desirable), then I would definitely try changing the PS1 variable referenced in Chris Dolan's answer; it resulted in significant speedups in certain operations.

猫腻 2024-10-15 08:32:08

我通过使用“以管理员身份运行”启动 cmd.exe 解决了 Windows 7 x64 上 Git 缓慢的问题。

I solved my slow Git problem on Windows 7 x64 by starting cmd.exe with "Run as administrator".

£烟消云散 2024-10-15 08:32:08

通过将 core.preloadindex 设置为 true 如此处推荐的

I saw a decent improvement by setting core.preloadindex to true as recommended here.

灯下孤影 2024-10-15 08:32:08

您还可以通过更改以下 Git 配置来获得后续性能提升:

git config --global status.submoduleSummary false

在 Window 7 x64 上运行简单的 git status 命令时,我的计算机运行时间超过 30 秒。定义此选项后,立即执行该命令。

按照下页中的说明激活 Git 自己的跟踪帮助我找到了问题的根源,这可能在您的安装中有所不同:
https://github.com/msysgit/msysgit/ wiki/诊断为什么 Git 这么慢

You might also gain a very subsquent performance boost by changing the following Git configuration:

git config --global status.submoduleSummary false

When running the simple git status command on Window 7 x64, it took my computer more than 30 seconds to run. After this option was defined, the command is immediate.

Activating Git's own tracing as explained in the following page helped me found the origin of the problem, which might differ in your installation:
https://github.com/msysgit/msysgit/wiki/Diagnosing-why-Git-is-so-slow

肤浅与狂妄 2024-10-15 08:32:08

只有在设备管理器中关闭 AMD Radeon Graphics(或 Intel Graphics)对我有帮助。

输入图像描述这里

我在这里找到了答案:
https://superuser.com/questions/1160349/git-is- Windows 上速度极慢#=

Only turning off AMD Radeon Graphics (or Intel Graphics) in Device Manager helped me.

enter image description here

I found the answer here:
https://superuser.com/questions/1160349/git-is-extremely-slow-on-windows#=

咿呀咿呀哟 2024-10-15 08:32:08

正如 Chris Dolan 和 Wilbert 的回答中所述,PS1 会减慢您的速度

我没有完全禁用(按照 Dolan 的建议)或使用 Wilbert 提供的脚本,而是使用速度更快的“哑 PS1”。

它使用 (git symbolic-ref -q HEAD || git rev-parse --short HEAD) 2> /dev/null

PS1='\033[33m\]\w \n\[\033[32m\]$((git symbolic-ref -q HEAD || git rev-parse -q --short HEAD) 2> /dev/null) \[\033[00m\]# '

在我的 Cygwin 上,这比 Wilbert 的“fast_Git_PS1”答案更快 - 200 毫秒 vs . 400 毫秒,所以它减少了你的即时迟缓。

它不像 __git_ps1 那样复杂 - 例如,当您 cd 进入 .git 目录等时,它不会更改提示,但对于正常的日常使用来说,它足够好而且速度很快。

这已在 Git 1.7.9(Cygwin,但它应该适用于任何平台)上进行了测试。

As noted in Chris Dolan's and Wilbert's answers, PS1 slows you down.

Rather than completely disabling (as suggested by Dolan) or using the script offered by Wilbert, I use a "dumb PS1" that is much faster.

It uses (git symbolic-ref -q HEAD || git rev-parse --short HEAD) 2> /dev/null:

PS1='\033[33m\]\w \n\[\033[32m\]$((git symbolic-ref -q HEAD || git rev-parse -q --short HEAD) 2> /dev/null) \[\033[00m\]# '

On my Cygwin, this is faster than Wilbert's "fast_Git_PS1" answer - 200 ms vs. 400 ms, so it shaves off a bit of your prompt sluggishness.

It isn't as sophisticated as __git_ps1 - for example it doesn't change the prompt when you cd into the .git directory, etc. but for normal everyday use it's good enough and fast.

This was tested on Git 1.7.9 (Cygwin, but it should work on any platform).

暮倦 2024-10-15 08:32:08

除了这些其他答案之外,我还通过使用并行子模块获取(自 2016 年初的 Git 2.8 开始)加速了具有多个子模块的项目。

这可以通过 git fetch --recurse-submodules -j8 来完成,并使用 git config --global submodule.fetchJobs 8 来设置,或者您拥有/想要的内核数量使用。

In addition to these other answers, I've sped up projects with multiple submodules by using parallel submodule fetching (since Git 2.8 in early 2016).

This can be done with git fetch --recurse-submodules -j8 and set with git config --global submodule.fetchJobs 8, or however many cores you have/want to use.

我的影子我的梦 2024-10-15 08:32:08

我在 Git Bash 和 Git GUI 中都遇到了同样的问题。这两个程序过去都运行得很好,但后来它们随机地变慢了,我不明白为什么。

事实证明,这是 Avast。 Avast 导致各种程序(包括我编写的程序)发生奇怪的事情,所以我暂时禁用了它,果然,Bash 现在运行得和 Linux 上一样快。我刚刚将 Git 程序文件文件夹 (C:\Program Files\Git) 添加到 Avast 排除列表中,现在它的运行速度与在 Linux 上一样快。

是的,我意识到防病毒软件不是原始帖子中的问题,但我只是将其放在这里,以防它对某人有用。

I was having the same problem, in both Git Bash and Git GUI. Both programs use to run nicely, but then they randomly slowed down to a crawl, and I couldn't figure out why.

As it turns out, it was Avast. Avast has caused odd things to happen to various programs (including programs I write), so I disabled it for a second, and sure enough, Bash now runs as fast as it does on Linux. I just added the Git program files folder (C:\Program Files\Git) to the Avast exclusion list, and now it runs as fast as it does on Linux.

And yes, I realize the antivirus software was not the issue in the original post, but I'll just put this here in case it's useful to someone.

久光 2024-10-15 08:32:08

综合答案:

  1. Wilbert's - PS1 中包含哪些信息
  2. sinelaw's - ()()
# https://unix.stackexchange.com/questions/140610/using-variables-to-store-terminal-color-codes-for-ps1/140618#140618
# https://unix.stackexchange.com/questions/124407/what-color-codes-can-i-use-in-my-ps1-prompt
# \033 is the same as \e
# 0;32 is the same as 32
CYAN="$(echo -e "\e[1;36m")"
GREEN="$(echo -e "\e[32m")"
YELLOW="$(echo -e "\e[33m")"
RESET="$(echo -e "\e[0m")"

# https://stackoverflow.com/questions/4485059/git-bash-is-extremely-slow-in-windows-7-x64/19500237#19500237
# https://stackoverflow.com/questions/4485059/git-bash-is-extremely-slow-in-windows-7-x64/13476961#13476961
# https://stackoverflow.com/questions/39518124/check-if-directory-is-git-repository-without-having-to-cd-into-it/39518382#39518382
fast_git_ps1 ()
{
    git -C . rev-parse 2>/dev/null && echo " ($((git symbolic-ref --short -q HEAD || git rev-parse -q --short HEAD) 2> /dev/null))"
}

# you need \] at the end for colors
# Don't set \[ at the beginning or ctrl+up for history will work strangely
PS1='${GREEN}\u@\h ${YELLOW}\w${CYAN}$(fast_git_ps1)${RESET}\] $ '

结果:

frowr@RWAMW36650 /c/projects/elm-math-孩子们(大师)$

Combined answers:

  1. Wilbert's - what info to include in PS1
  2. sinelaw's - (<branch_name>) or (<sha>)
# https://unix.stackexchange.com/questions/140610/using-variables-to-store-terminal-color-codes-for-ps1/140618#140618
# https://unix.stackexchange.com/questions/124407/what-color-codes-can-i-use-in-my-ps1-prompt
# \033 is the same as \e
# 0;32 is the same as 32
CYAN="$(echo -e "\e[1;36m")"
GREEN="$(echo -e "\e[32m")"
YELLOW="$(echo -e "\e[33m")"
RESET="$(echo -e "\e[0m")"

# https://stackoverflow.com/questions/4485059/git-bash-is-extremely-slow-in-windows-7-x64/19500237#19500237
# https://stackoverflow.com/questions/4485059/git-bash-is-extremely-slow-in-windows-7-x64/13476961#13476961
# https://stackoverflow.com/questions/39518124/check-if-directory-is-git-repository-without-having-to-cd-into-it/39518382#39518382
fast_git_ps1 ()
{
    git -C . rev-parse 2>/dev/null && echo " ($((git symbolic-ref --short -q HEAD || git rev-parse -q --short HEAD) 2> /dev/null))"
}

# you need \] at the end for colors
# Don't set \[ at the beginning or ctrl+up for history will work strangely
PS1='${GREEN}\u@\h ${YELLOW}\w${CYAN}$(fast_git_ps1)${RESET}\] $ '

Result:

frolowr@RWAMW36650 /c/projects/elm-math-kids (master) $

丢了幸福的猪 2024-10-15 08:32:08

在我的例子中,Git Bash 快捷方式设置为 Start in:%HOMEDRIVE%%HOMEPATH% (您可以通过右键单击 Git Bash 并选择属性来检查这一点)。这是网络驱动器。

解决方案是使其指向%HOME%。如果你没有它,你可以在环境变量中设置它,现在 Git Bash 应该快如闪电。

In my case, the Git Bash shortcut was set to Start in:%HOMEDRIVE%%HOMEPATH% (you can check this by right clicking Git Bash and selecting properties). This was the network drive.

The solution is to make it point to %HOME%. If you do not have it, you can set it up in the environment variables and now Git Bash should be lightning fast.

柏拉图鍀咏恒 2024-10-15 08:32:08

我在 Windows 7 x64 上以有限用户帐户运行 Git for Windows (msysgit) 时遇到了同样的问题相当长一段时间。

从我在这里和其他地方读到的内容来看,共同的主题似乎是缺乏管理权限和/或 UAC。由于 UAC 在我的系统上处于关闭状态,因此它试图在程序文件目录中写入/删除某些内容的解释对我来说最有意义。

无论如何,我已经通过使用 zipinstaller 安装便携式版本的 Git 1.8 解决了我的问题。请注意,我必须解压 .7z 分发文件并将其重新打包为 ZIP 文件才能使 zipinstaller 正常工作。我还必须手动将该目录添加到我的系统路径中。

现在的表现已经很好了。尽管它安装在 Program Files (x86) 目录中(我作为受限用户没有权限),但它似乎没有遇到同样的问题。

我将此归因于便携版本在写入/删除文件的位置上更加保守(可能就是这种情况),或者归因于从 1.7 升级到 1.8。我不会试图确定是哪一个原因,我只想说它现在工作得更好了,包括 Bash。

I've encountered the same problem running Git for Windows (msysgit) on Windows 7 x64 as a limited user account for quite some time.

From what I've read here and other places, the common theme seems to be the lack of administrative privileges and/or UAC. Since UAC is off on my system, the explanation that it is trying to write/delete something in the program files directory makes the most sense to me.

In any case, I've resolved my problem by installing the portable version of Git 1.8 with zipinstaller. Note that I had to unpack the .7z distribution file and repack it as a ZIP file in order for zipinstaller to work. I also had to manually add that directory to my system path.

The performance is fine now. Even though it is installed in the Program Files (x86) directory, which I don't have permissions for as a limited user, it doesn't seem to suffer from the same problem.

I ascribe this either to the fact that the portable version is a bit more conservative in where it writes/deletes files, which is probably the case, or to the upgrade from 1.7 to 1.8. I'm not going to try to pin down which one is the reason, suffice to say it works much better now, including Bash.

北方的巷 2024-10-15 08:32:08

就我而言,实际上是 Avast 防病毒软件导致 Git Bash 甚至 PowerShell 变得非常慢。

我首先尝试禁用 Avast 10 分钟,看看是否可以提高速度,结果确实如此。之后,我在 Avast 中添加了整个 Git Bash 安装目录作为例外,用于读取、写入和执行。就我而言,它是 C:\Program Files\Git\*

In my case, it actually was Avast antivirus leading to Git Bash and even PowerShell becoming really slow.

I first tried disabling Avast for 10 minutes to see if it improved the speed and it did. Afterwards, I added the entire Git Bash installation directory as an exception in Avast, for Read, Write and Execute. In my case that was C:\Program Files\Git\*.

泪之魂 2024-10-15 08:32:08

如果您通过 cmd 使用 Git,请尝试从 Git Bash 运行它。
在cmd中,git.exe实际上是一个包装器,每次启动它时都会设置正确的环境,然后才启动真正的git.exe。完成您想做的事情可能需要花费两倍的时间。而 Git Bash 仅在启动时才设置环境。

If you use Git from cmd, try running it from Git Bash.
In cmd, git.exe is actually a wrapper that sets up the correct environment every time you start it, and only then launches the real git.exe. It can take up to twice as much time as it's required to just do what you want. And Git Bash sets up the environment only when it starts.

谈场末日恋爱 2024-10-15 08:32:08

我也遇到过类似的情况,我的问题与 Active Directory 和 VPN 相关。

像这样工作了半年后发现了这个黄金:http://bjg.io/guide/cygwin -ad/

您基本上需要的只是在 /etc/nsswitch.conf 中禁用 db (您可以在 git 目录中找到它) passwd 和 group 部分,因此文件如下所示:

# Begin /etc/nsswitch.conf
passwd: files
group: files
db_enum: cache builtin
db_home: cygwin desc
db_shell: cygwin desc
db_gecos: cygwin desc
# End /etc/nsswitch.conf

然后更新本地密码和组设置一次:

$ mkpasswd -l -c > /etc/passwd
$ mkgroup -l -c > /etc/group

I've had similar situation and my problem was related to Active Directory and sitting behind vpn.

Found this gold after working like that for half a year: http://bjg.io/guide/cygwin-ad/

All you basicaly need is to disable db in /etc/nsswitch.conf (you can find it in your git directory) from passwd and group section, so the file looks like:

# Begin /etc/nsswitch.conf
passwd: files
group: files
db_enum: cache builtin
db_home: cygwin desc
db_shell: cygwin desc
db_gecos: cygwin desc
# End /etc/nsswitch.conf

and then update your local password and group settings once:

$ mkpasswd -l -c > /etc/passwd
$ mkgroup -l -c > /etc/group
思念满溢 2024-10-15 08:32:08

以上任何内容都无法帮助我。在我的场景中,问题是这样显示的:

  • 任何 ls -l 命令都很慢(大约需要 3 秒才能执行)
  • 任何后续的 ls -l 命令都会立即执行,但前提是在上一个 ls 命令之后的 45 秒内。

当使用 进程监视器发现每个命令之前都有一个DNS请求。

因此,一旦我禁用防火墙(在我的例子中是 Comodo)并让命令执行,问题就消失了。当防火墙重新打开时,它不会返回。我将尽早更新此响应,提供有关哪个进程正在执行阻止 DNS 请求以及目标是什么的更多详细信息。

Nothing of the above was able to help me. In my scenario the issue was showing itself like this:

  • Any ls -l command was slow (was taking about 3 seconds to execute)
  • Any subsequent ls -l command was executed instantly, but only if within 45 seconds from the previous ls command.

When it came to debugging with Process Monitor it was found that before every command there was a DNS request.

So as soon as I disabled my firewall (Comodo in my case) and let the command execute the issue is gone. And it is not returning back when the firewall was switched back on. With the earliest opportunity I'll update this response with more details about what process was doing a blocking DNS request and what was the target.

滴情不沾 2024-10-15 08:32:08

我的一位同事在 Windows 上使用 Git 时遇到了麻烦 (7) git status checkoutadd 很快,但是 git commit花了很长时间。

我们仍在尝试找到此问题的根本原因,但将存储库克隆到新文件夹中解决了他的问题。

A co-worker of mine had troubles with Git on Windows (7) git status checkout and add were fast, but git commit took ages.

We are still trying to find the root cause of this, but cloning the repository into a new folder fixed his problem.

女中豪杰 2024-10-15 08:32:08

正如许多人所说,这是因为 stash 是 Windows 上的 shell 脚本,但从 Git 2.18.0 开始,Windows 安装程序可以选择更快(约 90%)的内置实验功能。在藏匿版本中-
https://github.com/git-for-windows/build-额外/拉/203

As many said, this is due to stash being a shell script on Windows, but since Git 2.18.0 the Windows installer has an option for an experimental feature of a much faster (~90%) built-in version of stash -
https://github.com/git-for-windows/build-extra/pull/203.

还给你自由 2024-10-15 08:32:08

我从 git repo wiki 找到了两种有用的诊断方法:
https://github.com/git-for-windows/ git/wiki/Diagnosing-performance-issues

基本上,将 set -x 添加到 /etc/profile 的顶部,将回显实际执行的 shell 命令。这样您就可以找出哪个命令导致提示延迟。

但就我而言,主要是那些网络操作。我在 git 命令前面添加了 GIT_TRACE=1 ,以便它打印出正在执行的子 git 命令。

就我而言,我发现 git-credential-manager get 被执行了多次,并且每次调用都会等待几秒钟。因此,在谷歌搜索之后,我在管理模式下尝试了 git config --system --unset credential.helper 。 Sourcetree 现在很快,尽管我每次都需要在 git bash 中重新输入凭据。

有人怀疑是杀毒软件引起的,但现在无法证实。
https://github.com/Microsoft/Git-Credential- Manager-for-Windows/issues/786

I found out two helpful method to diagnose, from git repo wiki:
https://github.com/git-for-windows/git/wiki/Diagnosing-performance-issues

Basically, adding set -x to the top of <git install home>/etc/profile, will echo actual shell commands executed. This way you can find out which command is causing prompt delay.

But in my case, it was mainly those network operations. I prepended GIT_TRACE=1 to my git command, so that it prints out sub git commands it was executing.

In my case, I found out git-credential-manager get got executed multiple times, and each call waits over a few seconds. So after googling it, I tried git config --system --unset credential.helper in admin mode. Sourcetree is fast now, though I need to reenter credential each time in git bash.

Some suspect it was caused by antivirus, but I can't verify it now.
https://github.com/Microsoft/Git-Credential-Manager-for-Windows/issues/786

巴黎盛开的樱花 2024-10-15 08:32:08

我也遇到了 git PS1 缓慢的问题,尽管很长一段时间我认为这是一个数据库大小问题(大存储库),并且正在尝试各种 git gc 技巧,并且正在寻找其他原因,就像你。但是,就我而言,问题出在这一行:

function ps1_gitify
{
   status=$(git status 2>/dev/null )      # <--------------------
   if [[ $status =~ "fatal: Not a git repository" ]]
   then
       echo ""
   else
       echo "$(ps1_git_branch_name)  $(ps1_git_get_sha)"
  fi
}

为每个命令行状态行执行 git status 很慢。哎哟。这是我手写的东西。 时,我发现这是一个问题

export PS1='

当我尝试此处一个答案中提到的类似操作 。命令行速度快如闪电。

现在我正在使用这个:

function we_are_in_git_work_tree
{
    git rev-parse --is-inside-work-tree &> /dev/null
}

function ps1_gitify
{
    if ! we_are_in_git_work_tree
    then
    ...

来自堆栈溢出帖子PS1 线与 git 当前分支和颜色 并且工作正常。再次拥有快速的 Git 命令行。

当我尝试此处一个答案中提到的类似操作 。命令行速度快如闪电。

现在我正在使用这个:

来自堆栈溢出帖子PS1 线与 git 当前分支和颜色 并且工作正常。再次拥有快速的 Git 命令行。

I also had issue with git PS1 slowness, although for a long time I was thinking it's a database size problem (big repository) and was trying various git gc tricks, and were looking for other reasons, just like you. However, in my case, the problem was this line:

function ps1_gitify
{
   status=$(git status 2>/dev/null )      # <--------------------
   if [[ $status =~ "fatal: Not a git repository" ]]
   then
       echo ""
   else
       echo "$(ps1_git_branch_name)  $(ps1_git_get_sha)"
  fi
}

Doing the git status for every command line status line was slow. Ouch. It was something I wrote by hand. I saw that was a problem when I tried the

export PS1='

like mentioned in one answer here. The command line was lightning fast.

Now I'm using this:

function we_are_in_git_work_tree
{
    git rev-parse --is-inside-work-tree &> /dev/null
}

function ps1_gitify
{
    if ! we_are_in_git_work_tree
    then
    ...

From the Stack Overflow post PS1 line with git current branch and colors and it works fine. Again have a fast Git command line.

like mentioned in one answer here. The command line was lightning fast.

Now I'm using this:

From the Stack Overflow post PS1 line with git current branch and colors and it works fine. Again have a fast Git command line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文