问题
Git's tab autocompletion is useful for small projects, but I'm currently working on two big projects that use git and for these it's worse than useless. Whenever I type, say, git add forms<tab>
, git takes 20 seconds or more to find the file (in this example, forms.py), and in this timespan I can't do anything else in the terminal. Is there any way to turn off the autocompletion feature, or somehow make it faster?
回答1:
It's not git auto completing the file names, it's your shell. Do you have the same delay when doing e.g. "cat forms< tab >"?
Check out this post with similar problems:
http://talkings.org/post/5236392664/zsh-and-slow-git-completion
This post suggests adding the following to your .zshrc:
__git_files () {
_wanted files expl 'local files' _files
}
EDIT: Here's the original text of that post
I found many posts relating complaints about how painfully slow git auto-completion can be in large repositories. There were various suggested patches and suggestions to load the latest zsh. Maybe one of those things would work, but all I really want is for it to complete the names of branches and files as they are in the file system. I did not find any suggestions on how to get this behavior so I figured it out for myself. I thought I would share this for anyone who might benefit from it. I just added the following to my .zshrc file:
__git_files () { _wanted files expl 'local files' _files }
Now I can run git commands and get near instant completion while still getting file completion similar to what ls would provide.
回答2:
Finally fed up with terribly slow auto-completion in zshell and starting looking a solution. I ended up switching from 'git' to using the 'gitfast' plugin that is already installed w/ oh my zsh and am flying... https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#gitfast
回答3:
I have no experience with zshell, but I got this answer on another forum. You need to include this line in your .zshrc file:
compdef -d git
回答4:
This is because Zsh comes by default with extremely bloated completion for Git. I wrote a blog post explaining how I fixed this bloatedness, but it had to be outside of the Zsh project.
The easy answer is to install Git's zsh completion, which is different than Zsh's git completion (which comes by default). Download git-completion.zsh, and place it in your ~/.zsh/_git
. Then place it on your fpath:
fpath=(~/.zsh $fpath)
You should be flying now.
As another comment here explains; another option is to use oh-my-sh and enable the gitfast plugin, which achieves the same thing.
Why would Zsh developers insist on making their code slow? I don't know, but here you can see a sample of their reasoning: Re: Slowness issue with git completion.
回答5:
One very quick and dirty solution is to delete the following file responsible for the auto-completion.
/usr/local/git/contrib/completion/git-completion.bash
回答6:
According to the answer to git bash auto complete slow on windows 7 x64, git 2.13 comes with a faster git-completion.bash
来源:https://stackoverflow.com/questions/9810327/zsh-auto-completion-for-git-takes-significant-amount-of-time-can-i-turn-it-off