我正在开发一个相当大的 git 存储库,其中包含几千个(远程)分支。我习惯在控制台(在那种情况下是 Git Bash)中使用自动完成(使用 [TAB]),所以我也无意识地为 git 命令这样做。
例如我会输入
git checkout task[TAB]
控制台经常停顿几分钟。有没有办法将自动完成仅限于本地分支?
最佳答案
使用 Git 2.13(2017 年第二季度),您可以禁用(部分)分支完成。
git checkout --no-guess ...
# or:
export GIT_COMPLETION_CHECKOUT_NO_GUESS=1
参见 commit 60e71bb (2017 年 4 月 21 日)Jeff King ( peff
) .
(由 Junio C Hamano -- gitster
-- 在 commit b439747 中 merge ,2017 年 5 月 1 日)
如 contrib/completion/git-completion.bash
中所述现在:
You can set the following environment variables to influence the behavior of the completion routines:
GIT_COMPLETION_CHECKOUT_NO_GUESS
When set to "1", do not include "DWIM" suggestions in
git-checkout
completion (e.g., completing "foo" when "origin/foo" exists).
备注:DWIM is short for Do What I Mean ,系统会尝试预测用户打算做什么,自动纠正琐碎的错误,而不是盲目地执行用户明确但可能不正确的输入。
completion
: optionally disable checkout DWIMWhen we complete branch names for "
git checkout
", we also complete remote branch names that could trigger the DWIM behavior. Depending on your workflow and project, this can be either convenient or annoying.For instance, my clone of
gitster.git
contains 74 local "jk/*
" branches, but origin contains another 147.
When I want to checkout a local branch but can't quite remember the name, tab completion shows me 251 entries. And worse, for a topic that has been picked up for pu, the upstream branch name is likely to be similar to mine, leading to a high probability that I pick the wrong one and accidentally create a new branch.
注:“picked up for pu”:见What's cooking in git.git
: 它开始于:
Commits prefixed with '
-
' are only in 'pu
' (proposed updates) while commits prefixed with '+
' are in 'next
'.
这是 Git Workflow Graduation process 的一部分.
pu
(proposed updates) is an integration branch for things that are not quite ready for inclusion yet
This patch adds a way for the user to tell the completion code not to include DWIM suggestions for checkout.
This can already be done by typing:git checkout --no-guess jk/<TAB>
but that's rather cumbersome.
The downside, of course, is that you no longer get completion support when you do want to invoke the DWIM behavior.
But depending on your workflow, that may not be a big loss (for instance, in git.git I am much more likely to want to detach, so I'd type "git checkout origin/jk/<TAB>
" anyway).
关于windows - 在 Git Bash 中禁用远程分支的自动完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6623649/