How can I make git do the “did you mean” suggestion?

前端 未结 4 747
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 04:36

I type

git puhs

And git says:

kristian@office:~/myrepo$ git puhs
git: \'puhs\' is not a git command. See \'git --help\'

Did y         


        
相关标签:
4条回答
  • 2021-01-30 05:13

    According to git-config(1), you want to set help.autocorrect appropriately. For example, git config --global help.autocorrect 5 will make it wait half a second before running the command so you can see the message first.

    0 讨论(0)
  • 2021-01-30 05:26

    Also take a look at thefuck

    It can correct typos, and also perform suggestions. Not just limited to git.

    0 讨论(0)
  • 2021-01-30 05:27

    As an alternative to help.autocorrect: if you make the same typos all the time, you can create aliases for them in your .gitconfig file

    [alias]
        puhs = push
    

    (I do this with shell aliases too, where I can never seem to type mkae^H^H^H^Hmake correctly.)

    0 讨论(0)
  • 2021-01-30 05:32

    The autocorrect is nice, but my OCD-self needs a little more control over what's going on. So, I wrote a straightforward script that just chooses the first suggestion provided by git. You run the script after the failed command and use the built in bash history substitution "bang bang" syntax. Also, if you are typing something that could possibly have more than one command, this command lets you choose one other than the first option.

    It would look something like this,

    kristian@office:~/myrepo$ git puhs
    git: 'puhs' is not a git command. See 'git --help'
    
    Did you mean this?
          push
    
    kristian@office:~/myrepo$ idid !!
    Counting objects: 18, done.
    Delta compression using up to 32 threads.
    Compressing objects: 100% (10/10), done.
    Writing objects: 100% (10/10), 1.17 KiB, done.
    Total 10 (delta 6), reused 0 (delta 0)
    

    Plus, it's fun to type anything with two exclamation points. So bonus for that.

    Here's a gist with my script

    0 讨论(0)
提交回复
热议问题