CodeSmith CodeSmith - 1 year ago 58
Git Question

Why are there two different git commits for the same tag?

I'm trying to determine the commit SHA associated with a particular tag. When I execute

, I get the following output

$ git show-ref my_tag
6a390ca7bca7b52b2009069138873fdbc7922c1d refs/tags/my_tag

When I execute
I get this output

$ git rev-list -n 1 my_tag

The commit SHA's are different, but I don't understand why. It looks like
, generated by
, is the correct one. If I try and checkout the first commit with
git checkout 6a390c
and then look at the log, I'm not actually on
is displayed.

Can anyone explain why there might be a disconnect? Why am I redirected to
when I try and checkout
. And, most importantly, can I count on
git rev-list -n 1
to always show me the correct commit associated with a tag.


I also noticed that when I execute
git show my_tag
, I get output that looks like this

tag my_tag
Tagger: Me <>
Date: Mon Apr 4 14:43:46 2016 -0400

Tagging Release my_tag

tag my_tag_Build_1
Tagger: Me <>
Date: Thu Mar 31 10:46:18 2016 -0400

Tagging my_tag_Build_1

commit b6dcf8fa20296d146e9501ab9d25784879adeac8
Author: Me <>
Date: Wed Mar 30 18:12:10 2016 -0400

Remove secret_key_base values from secrets.yml

It's picking up two tags
. However, if I run
git tag
, the list of tags only has


If I run
git show my_tag_Build_1
, I get

fatal: ambiguous argument 'my_tag_Build_1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:

It seems like git is confused. Maybe the
tag existed at some point, but it doesn't seem to exist anymore.

Answer Source

You execute "git show my_tag" and see two tags because the my_tag tag was created using my_tag_Build_1 tag as parameter, like in the following command:

git tag -m "Tagging Release my_tag" -a my_tag my_tag_Build_1

On the other hand, I can't not explain why my_tag_Build_1 is not shown in the "git tag" command. This is really weird.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download