git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* determine name of tag used for checkout when multiple tags exist?
@ 2015-09-04  2:53 Jesse Hopkins
  2015-09-04  4:59 ` Jacob Keller
  2015-09-04  7:54 ` John Keeping
  0 siblings, 2 replies; 5+ messages in thread
From: Jesse Hopkins @ 2015-09-04  2:53 UTC (permalink / raw)
  To: git

Hello all,

Looking for suggestions on how to determine the tag that was used to
checkout a git repo to its associated commit, particularly in the case
where multiple tags might point to the same commit.

I've had a look at git-name-rev and git-describe, and both seem useful so
long as there's only one tag pointing to the commit of interest.  However,
I'm still coming up to speed on their behavior in the multiple tag case
(mainly by experimentation).

It seems to me that when checking out to a tag, Git does not record the
*name* of the tag anywhere, but rather sets HEAD to the de-referenced
commit SHA-1.  As far as I can tell, it is not possible to recover the
original name of the tag in the case of multiple tags on the same commit.
Is my conclusion correct?

The reason I ask is that we have a build environment where it is likely
that multiple tags will get set by various groups in our main 'truth' Git
repo.  We are using some scripting that would like to know the *name* of
the tag used for checkout (this has been working well for us so far as long
as we checkout against branches).

Is there perhaps some other means of doing a checkout to tag that DOES
record the name of the tag?  If not, I imagine we might need some external
means to record the checked out tag, which is not out of the question.

Regards,
Jesse

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: determine name of tag used for checkout when multiple tags exist?
  2015-09-04  2:53 determine name of tag used for checkout when multiple tags exist? Jesse Hopkins
@ 2015-09-04  4:59 ` Jacob Keller
  2015-09-04  7:54 ` John Keeping
  1 sibling, 0 replies; 5+ messages in thread
From: Jacob Keller @ 2015-09-04  4:59 UTC (permalink / raw)
  To: Jesse Hopkins; +Cc: Git List

On Thu, Sep 3, 2015 at 7:53 PM, Jesse Hopkins <jesse.hops@gmail.com> wrote:

>
> It seems to me that when checking out to a tag, Git does not record the
> *name* of the tag anywhere, but rather sets HEAD to the de-referenced
> commit SHA-1.  As far as I can tell, it is not possible to recover the
> original name of the tag in the case of multiple tags on the same commit.
> Is my conclusion correct?
>

I believe you are correct unless you check out to a branch named after
the tag? I don't believe it will actually store the tag as part of its
checkout.

Ie:

git checkout <tag>

may show "checked out at <tag>" via status, but that is only because
status uses describe to find that out..

I don't believe we store the information. You could recover it if you
know something about the format so as to distinquish them, ie: if you
only cared about annotated tags vs lightweight tags, for example.

Regards,
Jake

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: determine name of tag used for checkout when multiple tags exist?
  2015-09-04  2:53 determine name of tag used for checkout when multiple tags exist? Jesse Hopkins
  2015-09-04  4:59 ` Jacob Keller
@ 2015-09-04  7:54 ` John Keeping
       [not found]   ` <CAL3By-8ieAQPyR9k63_T5Fa9ZnAY8qSNZUpr_=fxebEcN=Zi7g@mail.gmail.com>
  1 sibling, 1 reply; 5+ messages in thread
From: John Keeping @ 2015-09-04  7:54 UTC (permalink / raw)
  To: Jesse Hopkins; +Cc: git

On Thu, Sep 03, 2015 at 08:53:16PM -0600, Jesse Hopkins wrote:
> Looking for suggestions on how to determine the tag that was used to
> checkout a git repo to its associated commit, particularly in the case
> where multiple tags might point to the same commit.
> 
> I've had a look at git-name-rev and git-describe, and both seem useful so
> long as there's only one tag pointing to the commit of interest.  However,
> I'm still coming up to speed on their behavior in the multiple tag case
> (mainly by experimentation).
> 
> It seems to me that when checking out to a tag, Git does not record the
> *name* of the tag anywhere, but rather sets HEAD to the de-referenced
> commit SHA-1.  As far as I can tell, it is not possible to recover the
> original name of the tag in the case of multiple tags on the same commit.
> Is my conclusion correct?
> 
> The reason I ask is that we have a build environment where it is likely
> that multiple tags will get set by various groups in our main 'truth' Git
> repo.  We are using some scripting that would like to know the *name* of
> the tag used for checkout (this has been working well for us so far as long
> as we checkout against branches).
> 
> Is there perhaps some other means of doing a checkout to tag that DOES
> record the name of the tag?  If not, I imagine we might need some external
> means to record the checked out tag, which is not out of the question.

Have you considered looking in the reflog?

When I checkout a tag, "git reflog -1" gives something like:

	989d251 HEAD@{0}: checkout: moving from master to v0.9.2

Since whitespace isn't permitted in tag names you can do something like:

	tag=$(git reflog -1)
	tag=${tag##* }
	git cat-file tag "$tag" >/dev/null 2>&1 || echo "not a tag!"

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: determine name of tag used for checkout when multiple tags exist?
       [not found]     ` <CAL3By-8cgAz1Jau3NO0kkHAVwvy3hPMMUn=xwUtY78TE5WE9vw@mail.gmail.com>
@ 2015-09-04 11:19       ` John Keeping
  2015-09-05 14:23         ` Jesse Hopkins
  0 siblings, 1 reply; 5+ messages in thread
From: John Keeping @ 2015-09-04 11:19 UTC (permalink / raw)
  To: Jesse Hopkins; +Cc: git

[It looks like your reply didn't get through to the mailing list,
 presumably because it contained a text/html part.]

On Fri, Sep 04, 2015 at 04:22:04AM -0600, Jesse Hopkins wrote:
> On Sep 4, 2015 1:54 AM, "John Keeping" <john@keeping.me.uk> wrote:
> > When I checkout a tag, "git reflog -1" gives something like:
> >
> >         989d251 HEAD@{0}: checkout: moving from master to v0.9.2
> >
> > Since whitespace isn't permitted in tag names you can do something like:
> >
> >         tag=$(git reflog -1)
> >         tag=${tag##* }
> >         git cat-file tag "$tag" >/dev/null 2>&1 || echo "not a tag!"
> 
> Thanks John that seems promising. One limitation it seems is that the
> reflog doesn't contain the tag name on a freshly cloned repo which used the
> tag as the -b option.   However it seems I can recover the tag name from
> the reflog so long as I clone against something other than the tag,  then
> checkout the tag.

I think it would be a reasonable enhancement to include the branch name
in the reflog message if "-b" is given to "git clone", but I'm not aware
of any (formal) policy on the format of reflog messages so relying on
any particular message may not be 100% reliable across Git upgrades.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: determine name of tag used for checkout when multiple tags exist?
  2015-09-04 11:19       ` John Keeping
@ 2015-09-05 14:23         ` Jesse Hopkins
  0 siblings, 0 replies; 5+ messages in thread
From: Jesse Hopkins @ 2015-09-05 14:23 UTC (permalink / raw)
  To: John Keeping; +Cc: git

On Fri, Sep 4, 2015 at 5:19 AM, John Keeping <john@keeping.me.uk> wrote:

> I think it would be a reasonable enhancement to include the branch name
> in the reflog message if "-b" is given to "git clone", but I'm not aware
> of any (formal) policy on the format of reflog messages so relying on
> any particular message may not be 100% reliable across Git upgrades.


Thanks for posting my dropped message.  Apparently the gmail Android
app doesn't do plain text.  I understand that parsing the reflog
message may not be future-proof, but I'm going to go for it.  I think
that will be more reliable than trying to track the tag name
externally.  Having the reflog message show up for a "-b" clone would
be helpful, but it will be easy enough for me to clone HEAD, then
immediately checkout the tag of interest.  Thanks again for the
suggestion, would've never thought use the reflog.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-05 14:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-04  2:53 determine name of tag used for checkout when multiple tags exist? Jesse Hopkins
2015-09-04  4:59 ` Jacob Keller
2015-09-04  7:54 ` John Keeping
     [not found]   ` <CAL3By-8ieAQPyR9k63_T5Fa9ZnAY8qSNZUpr_=fxebEcN=Zi7g@mail.gmail.com>
     [not found]     ` <CAL3By-8cgAz1Jau3NO0kkHAVwvy3hPMMUn=xwUtY78TE5WE9vw@mail.gmail.com>
2015-09-04 11:19       ` John Keeping
2015-09-05 14:23         ` Jesse Hopkins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).