Alex Rivera | Logout

git show HEAD^ doesn't seem to be working. Is this normal?

Asked 2011-05-23T00:47:23.453
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

Edit
Report

2 Answers

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.

answered 2013-05-31T19:45:50.003
9

You can also use noglob.

% noglob git show HEAD^ 

(or make an alias for noglob git)

answered 2013-06-13T10:21:44.297

Your Answer