Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 710
noli Avatar asked May 23 '11 00:05

noli


People also ask

How do I view heads in Git?

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.

What's the difference between head and head in Git?

The difference between HEAD^ (Caret) and HEAD~ (Tilde) is how they traverse history backwards from a specified starting point, in this particular case HEAD .

What is the head in Git?

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 .

What does Head @{ 3 refer to?

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.


1 Answers

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.

like image 88
Christopher Avatar answered Oct 21 '22 08:10

Christopher