From: John Keeping <john@keeping.me.uk>
To: Jesse Hopkins <jesse.hops@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: determine name of tag used for checkout when multiple tags exist?
Date: Fri, 4 Sep 2015 08:54:00 +0100 [thread overview]
Message-ID: <20150904075400.GA27660@serenity.lan> (raw)
In-Reply-To: <CAL3By-8odLE53iBiNATgiCcnK4Ef5uBeH7E6EMB1K7P-oX0oAQ@mail.gmail.com>
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!"
next prev parent reply other threads:[~2015-09-04 7:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
[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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150904075400.GA27660@serenity.lan \
--to=john@keeping.me.uk \
--cc=git@vger.kernel.org \
--cc=jesse.hops@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).