bash git show HEAD^ 似乎不起作用。这是正常的吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6091827/
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
git show HEAD^ doesn't seem to be working. Is this normal?
提问by noli
I'm using Zsh and and trying to run git show for a project to see my revision history. If I do
我正在使用 Zsh 并尝试为项目运行 git show 以查看我的修订历史记录。如果我做
git show HEAD
it works fine showing me my last commit, however the following commands don't work
它可以很好地向我展示我的最后一次提交,但是以下命令不起作用
[master↑5?]:~/project $ git show HEAD^
zsh: no matches found: HEAD^
[master↑5?]:~/project $ git show HEAD^^
zsh: no matches found: HEAD^^
However this does work
然而这确实有效
git HEAD~1
Am I doing something wrong here with git show HEAD^^?
我在这里做错了git show HEAD^^吗?
git version 1.7.4.5
git 版本 1.7.4.5
回答by Christopher
Instead of escaping or quoting the caret, you could just tell zshto stop bailing on the command when it fails to match a glob pattern. Put this option in your .zshrc:
与其转义或引用脱字符号,您还可以告诉zsh在命令与 glob 模式不匹配时停止执行命令。将此选项放在您的.zshrc:
setopt NO_NOMATCH
That option stops zshfrom aborting commands if glob-matching fails. git show HEAD^will work properly, and you needn't escape the caret. Furthermore, globbing and the ^event designatorwill still work the way you expect.
zsh如果全局匹配失败,该选项将停止中止命令。git show HEAD^将正常工作,您不必逃避插入符号。此外,通配符和^事件指示符仍将按您期望的方式工作。
To answer dolzenko's question in comments, you can get git log ^production master(which is, coincidentally, also exactly what git's 'double dot' syntax does: git log production..master) to work by disabling extended globbing:
要在评论中回答 dolzenko 的问题,您可以通过禁用扩展通配符来获得git log ^production master(巧合的是,这也正是 git 的“双点”语法所做的git log production..master:)工作:
setopt NO_EXTENDED_GLOB
Of course, you might actually rely on extended globbing and not know it. I recommend reading about what it doesbefore disabling it.
当然,您实际上可能依赖于扩展的通配符而不知道它。我建议你阅读关于它做什么禁用它。
回答by Johnsyweb
The carat (^) has special meaning in Bashand Zsh.
You'll need to escape it or quote it:
你需要转义它或引用它:
% git show HEAD\^
% git show 'HEAD^^'
回答by mb14
You can also use noglob.
您也可以使用 noglob。
% noglob git show HEAD^
(or make an alias for noglob git)
(或为 取别名noglob git)

