# Trouble with cat-file on tags

4 messages from 2016-04-01 to 2016-04-01. Participants: Sebastian Schuberth, Jeff King.
Thread: https://gitlist.dev/t/41896

## Sebastian Schuberth, 2016-04-01 09:26

Subject: Trouble with cat-file on tags
Message-ID: <ndlesh$dj1$1@ger.gmane.org>
URL: https://gitlist.dev/e/ndlesh%24dj1%241%40ger.gmane.org

```
Hi,

I was trying to use cat-file to get the hash of a tag object (not the hash of the commit object the tag points to), and I'm running into some issues. At the example of a cloned gerry [1] repository:

---8<---
$ git tag test-tag

$ git tag -l
test-tag
v0.0.3
v0.0.4
v0.1.0
v0.1.1
v0.1.2

$ git cat-file tag refs/tags/test-tag
fatal: git cat-file refs/tags/test-tag: bad file
---8<---

So for a newly created local tag, cat-file does not seem to work. However:

---8<---
$ git cat-file tag refs/tags/v0.1.2
object 91b0d21eba039e5ba0a90104c9c485735576dcbf
type commit
tag v0.1.2
tagger Travis Truman <travis_truman@cable.comcast.com> 1452693317 -0500

Version 0.1.2
---8<---

For an existing tag, git-file suddenly *does* seem to work, although I'm puzzled why I'm getting info on the commit object here. I thought "cat-file tag" should explicitly make "cat-file" list information about the tag object itself, not about the commit object the tag points to.

Thoughts?

[1] https://github.com/trumant/gerry

Regards,
Sebastian

```

## Sebastian Schuberth, 2016-04-01 09:32

Subject: Re: Trouble with cat-file on tags
Message-ID: <ndlf7q$ghe$1@ger.gmane.org>
URL: https://gitlist.dev/e/ndlf7q%24ghe%241%40ger.gmane.org
In-Reply-To: <ndlesh$dj1$1@ger.gmane.org>

```
On 4/1/2016 11:26, Sebastian Schuberth wrote:

> ---8<---
> $ git tag test-tag
>
> $ git tag -l
> test-tag
> v0.0.3
> v0.0.4
> v0.1.0
> v0.1.1
> v0.1.2
>
> $ git cat-file tag refs/tags/test-tag
> fatal: git cat-file refs/tags/test-tag: bad file
> ---8<---

Alright, I just found out why that is: Lighweight tags are not stored as 
Git objects. As soon as I make it an annoted tag by specifying a 
message, "cat-file tag" do esnot display a fatal error anymore.

However, I still get information about the commit oject iintsead of the 
tag object. Is this expected?

Regards,
Sebastian

```

## Sebastian Schuberth, 2016-04-01 10:00

Subject: Re: Trouble with cat-file on tags
Message-ID: <ndlgsc$ed7$1@ger.gmane.org>
URL: https://gitlist.dev/e/ndlgsc%24ed7%241%40ger.gmane.org
In-Reply-To: <ndlf7q$ghe$1@ger.gmane.org>

```
On 4/1/2016 11:32, Sebastian Schuberth wrote:

> However, I still get information about the commit oject iintsead of the
> tag object. Is this expected?

Solved this one, too: Yes it is. I was misreading the docs:

"If <type> is specified, the raw (though uncompressed) contents of the 
<object> will be returned."

This means

$ git cat-file tag refs/tags/v0.1.2

displays the *contents* of the tag, not the tag itself. Which leads me 
to the next question: For a given name of an annotated tag, how to get 
the hash of the tag object? The solution I found for now:

$ git show-ref --tags -- v0.1.2
92b67e2b0626519ef8cd4e9cacb2bdafba6d53f0 refs/tags/v0.1.2

Regards,
Sebastian

```

## Jeff King, 2016-04-01 12:26

Subject: Re: Trouble with cat-file on tags
Message-ID: <20160401122631.GA12019@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20160401122631.GA12019%40sigill.intra.peff.net
In-Reply-To: <ndlgsc$ed7$1@ger.gmane.org>

```
On Fri, Apr 01, 2016 at 12:00:44PM +0200, Sebastian Schuberth wrote:

> This means
> 
> $ git cat-file tag refs/tags/v0.1.2
> 
> displays the *contents* of the tag, not the tag itself.

Right. `cat-file` is about looking at object content.

> Which leads me to
> the next question: For a given name of an annotated tag, how to get the hash
> of the tag object? The solution I found for now:
> 
> $ git show-ref --tags -- v0.1.2
> 92b67e2b0626519ef8cd4e9cacb2bdafba6d53f0 refs/tags/v0.1.2

Here you just want to resolve the ref, without looking at the object.
The canonical way is:

  git rev-parse --verify v0.1.2

You can also use that to peel the tag to a commit, or a commit to a tree
(e.g., with "v0.1.2^{commit}").

-Peff

```
