简体   繁体   English

Windows 上的 Git Bash 的“git branch”命令很慢

[英]"git branch" command is slow from Git Bash on Windows

I only have one branch main but when I execute the git branch command, it took about 30 seconds to complete.我只有一个分支main但是当我执行git branch命令时,大约需要 30 秒才能完成。 Other commands like git status does not have this performance issue.其他命令如git status没有这个性能问题。 What are some of the things that I can check here?我可以在这里检查哪些内容?

Git version is 2.36.0 running on Windows 10. Git 版本是在 Windows 10 上运行的 2.36.0。

UPDATE:更新:

  • Also opening up Git Bash is slow (around 20 seconds).打开 Git Bash 也很慢(大约 20 秒)。 I tried the solution https://stackoverflow.com/a/47542488/1160753 .我尝试了解决方案https://stackoverflow.com/a/47542488/1160753 Git Bash opened up quickly after that change but the subsequent action of opening up the Git Bash is back to take approximately 20 seconds.更改后 Git Bash 快速打开,但打开 Git Bash 的后续操作又需要大约 20 秒。
  • When Git Bash is executed under "Run As Administrator", git branch completed quickly.在“以管理员身份运行”下执行 Git Bash 时, git branch很快完成。 BUT that is not every single time.但这不是每一次。 There are times that the same command takes 30 seconds to complete (this is without any additional branch)有时相同的命令需要 30 秒才能完成(这是没有任何额外的分支)

Tl;dr Tl;博士

On Windows, when the PC is in a domain, make sure that the domain controller is reachable.在 Windows 上,当 PC 在域中时,请确保域控制器可访问。

Details细节

The shell and command line tools that are distributed with Git for Windows are derived from the MSYS2 project , which is based on a variant of the Cygwin library.与 Git for Windows 一起分发的 shell 和命令行工具源自MSYS2 项目,该项目基于 Cygwin 库的变体。 As part of the program startup routine, the library does several name lookups.作为程序启动例程的一部分,该库会进行多次名称查找。 When the system is registered in a domain, this lookup goes to the domain controller.当系统在域中注册时,此查找将转到域控制器。 In the case when the domain controller is not reachable, the lookup waits for time-outs.在无法访问域控制器的情况下,查找会等待超时。 This causes the delays.这会导致延迟。

The results of the lookup is cached by Windows.查找的结果由 Windows 缓存。 Therefore for a short time, subsequent startups do not have to wait for the time-outs.因此,在短时间内,后续启动不必等待超时。 But ultimately the cache expires and the next program invocation has to wait again.但最终缓存到期,下一次程序调用必须再次等待。

The Git program, git.exe , is not based on the Cygwin library and does not need the name lookup. Git 程序git.exe不是基于 Cygwin 库,也不需要名称查找。 It can run without delay.它可以毫无延迟地运行。 However, many Git commands spawn a pager, typically less , which does suffer from the delay;然而,许多 Git 命令会产生一个寻呼机,通常是less ,它确实会受到延迟的影响; therefore, it appears as if Git itself would be delayed.因此,看起来 Git 本身会被延迟。 (Not that it matters; the user experience is bad either way.) (没关系;无论哪种方式,用户体验都很糟糕。)

On top of that there are many other cases where Git runs a command line tool: hooks, textconv filters, ssh, etc. All of them can suffer from the delay.除此之外,还有许多其他 Git 运行命令行工具的情况:钩子、textconv 过滤器、ssh 等。所有这些都可能受到延迟的影响。

EDIT: I am currently testing the following change.编辑:我目前正在测试以下更改。 Do NOT make this change to your system unless you know exactly what the security implications are.除非您确切知道安全隐患是什么,否则不要对您的系统进行此更改。

I used mkpasswd and mkgroup to cache the current domain information locally:我使用mkpasswdmkgroup在本地缓存当前域信息:

mkpasswd >> /etc/passwd
mkgroup >> /etc/group

Then I removed duplicates from the files.然后我从文件中删除了重复项。 (But /etc/group did not exist before these commands.) (但/etc/group在这些命令之前不存在。)

This idea was taken from the Cygwin FAQ .这个想法取自Cygwin FAQ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM