Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

like image 642
pktangyue Avatar asked Apr 28 '13 09:04

pktangyue


People also ask

How do I pop a specific stash in git?

To pop a specific stash in git, you can use the git stash apply command followed by the stash@{NUMBER} command. command. It will show the list of stashes you have saved.

How do I see all stash in git?

The Git stash list command will pull up a list of your repository's stashes. Git will display all of your stashes and a corresponding stash index. Now, if you wish to view the contents of a specific stash, you can run the Git stash show command followed by stash@ and the desired index.

Does git stash apply pop the stash?

Retrieving stashed changesYou can reapply stashed changes with the commands git stash apply and git stash pop . Both commands reapply the changes stashed in the latest stash (that is, stash@{0} ). A stash reapplies the changes while pop removes the changes from the stash and reapplies them to the working copy.

How do you pop named stash?

use git stash push -m aNameForYourStash to save it. Then use git stash list to learn the index of the stash that you want to apply. Then use git stash pop --index 0 to pop the stash and apply it.


1 Answers

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

like image 142
bond Avatar answered Sep 28 '22 08:09

bond