简体   繁体   English

OSX 终端在 git 存储库中运行缓慢

[英]OSX terminal running slow in git repositories

I've noticed that whenever I type a command within a local git repository it takes around 7-8 seconds to register keystrokes and another 7-8 seconds to begin running the command.我注意到,每当我在本地 git 存储库中键入命令时,注册击键大约需要 7-8 秒,然后开始运行命令需要 7-8 秒。 I've checked my logs from other apps like anti-virus software and haven't found anything obscenely large.我检查了其他应用程序(如防病毒软件)的日志,并没有发现任何大得惊人的东西。 I use iTerm, but I've also checked that the exact same thing happens when using Terminal.我使用 iTerm,但我也检查了使用终端时是否发生了完全相同的事情。

Any ideas on what the problem could be?关于问题可能是什么的任何想法?

If it helps, I'm on OSX Yosemite.如果有帮助,我在 OSX Yosemite 上。

Most likely, you have something running in your shell prompt which checks and reports the repository's current state.最有可能的是,您在 shell 提示符下运行了一些检查和报告存储库当前状态的东西。 Many shell frameworks will do this (such as oh-my-zsh, or bash-it).许多 shell 框架会这样做(例如 oh-my-zsh 或 bash-it)。 They check the state of the repository every time a prompt is displayed.每次显示提示时,他们都会检查存储库的状态。

If you are in a repository that is for some reason very slow to report its status, that might display this behavior.如果您所在的存储库由于某种原因报告其状态很慢,则可能会显示此行为。 Some possible reasons include:一些可能的原因包括:

  • The repository is on a storage device (disk, USB stick, NAS) which is experiencing a problem, and is slow to respond.存储库位于遇到问题且响应缓慢的存储设备(磁盘、USB 记忆棒、NAS)上。

  • The repository is on a network-mounted filesystem which is slow to respond.存储库位于响应缓慢的网络安装文件系统上。

  • The repository is on a low-performance filesystem mount, such as mounted into a virtual machine.存储库位于低性能文件系统挂载上,例如挂载到虚拟机中。

运行git status然后推送一些新更改似乎加快了 iterm 对我的响应。

Please make sure you don't have large directories that are unnecessary to stay on your git cache.请确保您的 git 缓存中没有不必要的大目录。 It is a good practice to exclude compilation directory that contain large binaries from version control (directories like bin, obj, etc.).最好从版本控制中排除包含大型二进制文件的编译目录(bin、obj 等目录)。 In case you are using nodejs, sometimes node_modules gets extremely large, and it is a good idea to remove it from git.如果您使用的是 nodejs,有时 node_modules 会变得非常大,最好将其从 git 中删除。

git rm --cached -r node_modules git rm --cached -r node_modules

Then dont forget to add those directories to .gitignore然后不要忘记将这些目录添加到 .gitignore

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

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