windows - 在 Git Bash 中禁用远程分支的自动完成?

标签 windows git

我正在开发一个相当大的 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 DWIM

When 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/

相关文章:

windows - 如何在批处理文件中获取一年中的某一天

c++ - Windows.h - 焦点进入文本输入时的通知

windows - 批处理文件从 exe 获取返回值

Git LFS 和 HTTP 客户端身份验证

c++ - 在 Linux for Windows 上交叉编译 Qt5

c++ - GetUserDefaultUILanguage API 在 Win8.1(加拿大法语)上返回不正确的语言

git - 协调具有不同哈希的提交

git - 用于 git 提交的 Shell 脚本助手

git - 删除已从提交历史记录中推送的提交

git - 解决 merge 冲突 : Force overwrite all files