7

首先我输入git stash show.

然后输入sand tab,它显示git stash show stash@{,到目前为止它工作正常。

但是在我输入1and之后tab,它变成了git stash show stashstash@{1},而且很明显是错误的。

我认为.git-completion.bash中的以下代码可能有一些错误,但我几乎看不懂。

_git_stash ()
{
    local save_opts='--keep-index --no-keep-index --quiet --patch'
    local subcommands='save list show apply clear drop pop create branch'
    local subcommand="$(__git_find_on_cmdline "$subcommands")"
    if [ -z "$subcommand" ]; then
        case "$cur" in
        --*)
            __gitcomp "$save_opts"
            ;;
        *)
            if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
                __gitcomp "$subcommands"
            else
                COMPREPLY=()
            fi
            ;;
        esac
    else
        case "$subcommand,$cur" in
        save,--*)
            __gitcomp "$save_opts"
            ;;
        apply,--*|pop,--*)
            __gitcomp "--index --quiet"
            ;;
        show,--*|drop,--*|branch,--*)
            COMPREPLY=()
            ;;
        show,*|apply,*|drop,*|pop,*|branch,*)
            __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \                                                               
                    | sed -n -e 's/:.*//p')"
            ;;
        *)
            COMPREPLY=()
            ;;
        esac
    fi
}

有谁知道如何修理它?

Bash 版本:GNU bash,版本 4.2.37(2)-release (i386-apple-darwin12.0.0)。

git版本:1.8.0.3

整个来源:https ://gist.github.com/pktangyue/5477924

4

2 回答 2

1

当我手动下载过时的 git 完成脚本时,我遇到了同样的问题。我能够通过使用自制软件获得最新版本来修复它。

brew install git bash-completion

删除您的“.profile”中可能拥有的旧链接。替换以使用 brew 中的脚本

if [ -f $(brew --prefix)/etc/bash_completion ]; then
    . $(brew --prefix)/etc/bash_completion
fi

现在,当我点击时,它会正确完成。(git stash show stash@{0 .. 给出 git stash show stash@{0})

于 2015-03-31T14:32:08.077 回答
0

Bash-Completion 应该作为一个单独的包或多或少独立于 Bash 本身。例如,我有来自 Cygwin 的 bash 版本 4.1.10-4 和 bash-completion 版本 1.3-1,并且您描述的完成功能可以正常工作。

请检查您安装的 Bash-Completion 版本。您也可以尝试直接从http://bash-completion.alioth.debian.org/安装最新版本,或者尝试仅将文件替换/etc/bash_completion.d/git为上游版本。

于 2013-05-13T08:55:43.230 回答