我怎样才能让 git 执行“你的意思是”建议?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5167367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I make git do the "did you mean" suggestion?
提问by krosenvold
I type
我打字
git puhs
And git says:
和 git 说:
kristian@office:~/myrepo$ git puhs
git: 'puhs' is not a git command. See 'git --help'
Did you mean this?
push
What is the config setting to make git just do the suggested command if it only has one suggestion ?
如果只有一个建议,让 git 只执行建议的命令的配置设置是什么?
回答by jamessan
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.
根据git-config(1),您要进行help.autocorrect
适当的设置。例如,git config --global help.autocorrect 5
让它在运行命令前等待半秒,以便您可以先看到消息。
回答by Ben
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.
自动更正很好,但我的强迫症自我需要对正在发生的事情有更多的控制。所以,我写了一个简单的脚本,只选择了 git 提供的第一个建议。在失败的命令之后运行脚本并使用内置的 bash 历史替换“bang bang”语法。此外,如果您键入的内容可能有多个命令,则此命令可让您选择第一个选项以外的选项。
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
回答by bstpierre
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
作为 help.autocorrect 的替代方法:如果你总是犯同样的错别字,你可以在你的 .gitconfig 文件中为它们创建别名
[alias]
puhs = push
(I do this with shell aliases too, where I can never seem to type mkae^H^H^H^Hmake
correctly.)
(我也使用 shell 别名来执行此操作,但我似乎永远无法mkae^H^H^H^Hmake
正确键入。)