Autocomplete issue while typing git stash show stash@{1}

First I type git stash show.

Then type s and tab, and it shows git stash show stash@{, till now it works fine.

  • Homebrew’s `git` not using completion
  • How can I configure zsh to autocomplete branch names while using 'git checkout'?
  • Add tab completion for Git branches in Powershell
  • Git aliases - command line autocompletion of branch names
  • Can I setup auto-complete for git on Windows via cmd.exe?
  • Is there a way to get git to autocomplete commands based on a shortened version?
  • But after I type 1 and tab, it becames git stash show stashstash@{1}, and it is obvious wrong.

    I think there may be some wrong in the following code in .git-completion.bash, but I can hardly read this.

    _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
    }
    

    Does anyone know how to fix it?

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

    git version: 1.8.0.3

    whole source: https://gist.github.com/pktangyue/5477924

  • git- strange characters in output (msys-git)
  • Which output format of Libre Office can I use to track the history of my files?
  • Why does git pull hang?
  • A better way to do git clone
  • Git:nothing added to commit but untracked files present
  • Creating a git repository in a parent folder of another git repository and removing the child repository but integrating its history into the parent
  • 2 Solutions collect form web for “Autocomplete issue while typing git stash show stash@{1}”

    Bash-Completion should come as a separate package more or less independent of Bash itself. For example I have bash version 4.1.10-4 and bash-completion version 1.3-1 from Cygwin and the completion you describe works as it should.

    Please check what version of Bash-Completion you have installed. You could also try to install the latest version directly from http://bash-completion.alioth.debian.org/ or try to replace only the file /etc/bash_completion.d/git with the upstream version.

    I had the same problem when I manually downloaded git completion script which was outdated. I was able to fix it by getting the latest using homebrew.

    brew install git bash-completion
    

    Remove old links that you may have in your “.profile”. Replace to use the script from brew

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

    Now when I tab on, it completes correctly. (git stash show stash@{0 .. gives git stash show stash@{0})

    Git Baby is a git and github fan, let's start git clone.