25

I'm using Zsh and and trying to run git show for a project to see my revision history. If I do

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 version 1.7.4.5

noli
  • 15,687
  • 8
  • 45
  • 59

3 Answers3

38

Instead of escaping or quoting the caret, you could just tell zsh to stop bailing on the command when it fails to match a glob pattern. Put this option in your .zshrc:

setopt NO_NOMATCH 

That option stops zsh from aborting commands if glob-matching fails. git show HEAD^ will work properly, and you needn't escape the caret. Furthermore, globbing and the ^ event designator will still work the way you expect.

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:

setopt NO_EXTENDED_GLOB

Of course, you might actually rely on extended globbing and not know it. I recommend reading about what it does before disabling it.

Christopher
  • 40,100
  • 10
  • 77
  • 96
  • Do you know why it doesn't work for things like, e.g. `git log ^production master --no-merges`? – dolzenko Jul 29 '13 at 14:19
  • @dolzenko: Edited the answer. If you don't want to turn off extended globbing, just use the double dot syntax. – Christopher Jul 29 '13 at 16:38
  • Working link for extended globbing article: https://www.refining-linux.org/archives/37-ZSH-Gem-2-Extended-globbing-and-expansion.html – rgin Nov 07 '19 at 09:59
32

The carat (^) has special meaning in Bash and Zsh.

You'll need to escape it or quote it:

% git show HEAD\^

% git show 'HEAD^^'
Community
  • 1
  • 1
johnsyweb
  • 129,524
  • 23
  • 177
  • 239
9

You can also use noglob.

% noglob git show HEAD^ 

(or make an alias for noglob git)

mb14
  • 21,602
  • 5
  • 56
  • 100