CodeSmith CodeSmith - 2 months ago 10
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

show-ref
, I get the following output

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


When I execute
rev-list
I get this output

$ git rev-list -n 1 my_tag
b6dcf8fa20296d146e9501ab9d25784879adeac8


The commit SHA's are different, but I don't understand why. It looks like
b6dcf8
, generated by
rev-list
, 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
6a390c
;
b6dcf8
is displayed.

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

Update

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

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

Tagging Release my_tag

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

Tagging my_tag_Build_1

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

Remove secret_key_base values from secrets.yml


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

my_tag


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
my_tag_Build_1
tag existed at some point, but it doesn't seem to exist anymore.

Answer

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.

Comments