{"thread":{"id":"40270","subject":"determine name of tag used for checkout when multiple tags exist?","startedAt":"2015-09-04T02:53:16Z","lastAt":"2015-09-05T14:23:03Z","messageCount":5,"participants":["Jesse Hopkins","Jacob Keller","John Keeping"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"269394","messageId":"CAL3By-8odLE53iBiNATgiCcnK4Ef5uBeH7E6EMB1K7P-oX0oAQ@mail.gmail.com","threadId":"40270","inReplyTo":null,"subject":"determine name of tag used for checkout when multiple tags exist?","fromName":"Jesse Hopkins","fromEmail":"jesse.hops@gmail.com","sentAt":"2015-09-04T02:53:16Z","receivedAt":"2015-09-04T02:53:16Z","isPatch":false,"sender":{"key":"jesse.hops@gmail.com","avatar":null},"body":"Hello all,\n\nLooking for suggestions on how to determine the tag that was used to\ncheckout a git repo to its associated commit, particularly in the case\nwhere multiple tags might point to the same commit.\n\nI've had a look at git-name-rev and git-describe, and both seem useful so\nlong as there's only one tag pointing to the commit of interest.  However,\nI'm still coming up to speed on their behavior in the multiple tag case\n(mainly by experimentation).\n\nIt seems to me that when checking out to a tag, Git does not record the\n*name* of the tag anywhere, but rather sets HEAD to the de-referenced\ncommit SHA-1.  As far as I can tell, it is not possible to recover the\noriginal name of the tag in the case of multiple tags on the same commit.\nIs my conclusion correct?\n\nThe reason I ask is that we have a build environment where it is likely\nthat multiple tags will get set by various groups in our main 'truth' Git\nrepo.  We are using some scripting that would like to know the *name* of\nthe tag used for checkout (this has been working well for us so far as long\nas we checkout against branches).\n\nIs there perhaps some other means of doing a checkout to tag that DOES\nrecord the name of the tag?  If not, I imagine we might need some external\nmeans to record the checked out tag, which is not out of the question.\n\nRegards,\nJesse\n"},{"id":"269397","messageId":"CA+P7+xo8BM1hCnkh3pa65eF=qne3yybTBCoBY3mqm8FfzwdShg@mail.gmail.com","threadId":"40270","inReplyTo":"CAL3By-8odLE53iBiNATgiCcnK4Ef5uBeH7E6EMB1K7P-oX0oAQ@mail.gmail.com","subject":"Re: determine name of tag used for checkout when multiple tags exist?","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2015-09-04T04:59:53Z","receivedAt":"2015-09-04T04:59:53Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Thu, Sep 3, 2015 at 7:53 PM, Jesse Hopkins <jesse.hops@gmail.com> wrote:\n\n>\n> It seems to me that when checking out to a tag, Git does not record the\n> *name* of the tag anywhere, but rather sets HEAD to the de-referenced\n> commit SHA-1.  As far as I can tell, it is not possible to recover the\n> original name of the tag in the case of multiple tags on the same commit.\n> Is my conclusion correct?\n>\n\nI believe you are correct unless you check out to a branch named after\nthe tag? I don't believe it will actually store the tag as part of its\ncheckout.\n\nIe:\n\ngit checkout <tag>\n\nmay show \"checked out at <tag>\" via status, but that is only because\nstatus uses describe to find that out..\n\nI don't believe we store the information. You could recover it if you\nknow something about the format so as to distinquish them, ie: if you\nonly cared about annotated tags vs lightweight tags, for example.\n\nRegards,\nJake\n"},{"id":"269403","messageId":"20150904075400.GA27660@serenity.lan","threadId":"40270","inReplyTo":"CAL3By-8odLE53iBiNATgiCcnK4Ef5uBeH7E6EMB1K7P-oX0oAQ@mail.gmail.com","subject":"Re: determine name of tag used for checkout when multiple tags exist?","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2015-09-04T07:54:00Z","receivedAt":"2015-09-04T07:54:00Z","isPatch":false,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Thu, Sep 03, 2015 at 08:53:16PM -0600, Jesse Hopkins wrote:\n> Looking for suggestions on how to determine the tag that was used to\n> checkout a git repo to its associated commit, particularly in the case\n> where multiple tags might point to the same commit.\n> \n> I've had a look at git-name-rev and git-describe, and both seem useful so\n> long as there's only one tag pointing to the commit of interest.  However,\n> I'm still coming up to speed on their behavior in the multiple tag case\n> (mainly by experimentation).\n> \n> It seems to me that when checking out to a tag, Git does not record the\n> *name* of the tag anywhere, but rather sets HEAD to the de-referenced\n> commit SHA-1.  As far as I can tell, it is not possible to recover the\n> original name of the tag in the case of multiple tags on the same commit.\n> Is my conclusion correct?\n> \n> The reason I ask is that we have a build environment where it is likely\n> that multiple tags will get set by various groups in our main 'truth' Git\n> repo.  We are using some scripting that would like to know the *name* of\n> the tag used for checkout (this has been working well for us so far as long\n> as we checkout against branches).\n> \n> Is there perhaps some other means of doing a checkout to tag that DOES\n> record the name of the tag?  If not, I imagine we might need some external\n> means to record the checked out tag, which is not out of the question.\n\nHave you considered looking in the reflog?\n\nWhen I checkout a tag, \"git reflog -1\" gives something like:\n\n\t989d251 HEAD@{0}: checkout: moving from master to v0.9.2\n\nSince whitespace isn't permitted in tag names you can do something like:\n\n\ttag=$(git reflog -1)\n\ttag=${tag##* }\n\tgit cat-file tag \"$tag\" >/dev/null 2>&1 || echo \"not a tag!\"\n"},{"id":"269410","messageId":"20150904111915.GB27660@serenity.lan","threadId":"40270","inReplyTo":"CAL3By-8cgAz1Jau3NO0kkHAVwvy3hPMMUn=xwUtY78TE5WE9vw@mail.gmail.com","subject":"Re: determine name of tag used for checkout when multiple tags exist?","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2015-09-04T11:19:15Z","receivedAt":"2015-09-04T11:19:15Z","isPatch":false,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"[It looks like your reply didn't get through to the mailing list,\n presumably because it contained a text/html part.]\n\nOn Fri, Sep 04, 2015 at 04:22:04AM -0600, Jesse Hopkins wrote:\n> On Sep 4, 2015 1:54 AM, \"John Keeping\" <john@keeping.me.uk> wrote:\n> > When I checkout a tag, \"git reflog -1\" gives something like:\n> >\n> >         989d251 HEAD@{0}: checkout: moving from master to v0.9.2\n> >\n> > Since whitespace isn't permitted in tag names you can do something like:\n> >\n> >         tag=$(git reflog -1)\n> >         tag=${tag##* }\n> >         git cat-file tag \"$tag\" >/dev/null 2>&1 || echo \"not a tag!\"\n> \n> Thanks John that seems promising. One limitation it seems is that the\n> reflog doesn't contain the tag name on a freshly cloned repo which used the\n> tag as the -b option.   However it seems I can recover the tag name from\n> the reflog so long as I clone against something other than the tag,  then\n> checkout the tag.\n\nI think it would be a reasonable enhancement to include the branch name\nin the reflog message if \"-b\" is given to \"git clone\", but I'm not aware\nof any (formal) policy on the format of reflog messages so relying on\nany particular message may not be 100% reliable across Git upgrades.\n"},{"id":"269493","messageId":"CAL3By-9e2ZjShFxMKoLfc_q0LFvB51m15Z8Ydp8b8fGNdcUp_A@mail.gmail.com","threadId":"40270","inReplyTo":"20150904111915.GB27660@serenity.lan","subject":"Re: determine name of tag used for checkout when multiple tags exist?","fromName":"Jesse Hopkins","fromEmail":"jesse.hops@gmail.com","sentAt":"2015-09-05T14:23:03Z","receivedAt":"2015-09-05T14:23:03Z","isPatch":false,"sender":{"key":"jesse.hops@gmail.com","avatar":null},"body":"On Fri, Sep 4, 2015 at 5:19 AM, John Keeping <john@keeping.me.uk> wrote:\n\n> I think it would be a reasonable enhancement to include the branch name\n> in the reflog message if \"-b\" is given to \"git clone\", but I'm not aware\n> of any (formal) policy on the format of reflog messages so relying on\n> any particular message may not be 100% reliable across Git upgrades.\n\n\nThanks for posting my dropped message.  Apparently the gmail Android\napp doesn't do plain text.  I understand that parsing the reflog\nmessage may not be future-proof, but I'm going to go for it.  I think\nthat will be more reliable than trying to track the tag name\nexternally.  Having the reflog message show up for a \"-b\" clone would\nbe helpful, but it will be easy enough for me to clone HEAD, then\nimmediately checkout the tag of interest.  Thanks again for the\nsuggestion, would've never thought use the reflog.\n"}]}