Hazok
Hazok

Reputation: 5593

Why does git show-ref --hash -- HEAD show a different sha1 than HEAD?

I'm going to use git rev-parse instead, but I am curious as to why the following command is giving me a different commit ID than I expect.

I wanted to pull the sha1 from HEAD in some scripts I'm writing. I was playing around with show-ref and rev-parse for this. What's curious to me is that using show-ref on HEAD shows a completely different sha1 than what is actually at HEAD. Using git rev-parse does not have this issue. Consider the following:

> git show-ref --hash -- HEAD
40f3fb3d84b7c9857cadb581b901e3cc20ed1f24
> git rev-parse HEAD
a54b2714e6052ba063ea45924610e2cf0b6e5750

It seems the two above statements should return the same commit ID. Why is there the difference?

Upvotes: 2

Views: 433

Answers (1)

Hazok
Hazok

Reputation: 5593

So, it turns out that someone actually pushed a remove branch called HEAD to the remote and is where I was getting the other commit ID when doing show-ref. When looking closer at show-ref, it actually asks for a pattern and is matching origin/HEAD.

Upvotes: 1

Related Questions