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
You can view your repository's heads in the path . git/refs/heads/ . In this path you will find one file for each branch, and the content in each file will be the commit ID of the tip (most recent commit) of that branch.
The difference between HEAD^ (Caret) and HEAD~ (Tilde) is how they traverse history backwards from a specified starting point, in this particular case HEAD .
When working with Git, only one branch can be checked out at a time - and this is what's called the "HEAD" branch. Often, this is also referred to as the "active" or "current" branch. Git makes note of this current branch in a file located inside the Git repository, in . git/HEAD .
ref~2 means the commit's first parent's first parent. ref~3 means the commit's first parent's first parent's first parent. And so on. ref^ is shorthand for ref^1 and means the commit's first parent.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With