git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: determine name of tag used for checkout when multiple tags exist?

From
John Keeping <john@keeping.me.uk>
Date
Sep 4, 2015, 11:19 UTC
Message-ID
<20150904111915.GB27660@serenity.lan>
In-Reply-To
<CAL3By-8cgAz1Jau3NO0kkHAVwvy3hPMMUn=xwUtY78TE5WE9vw@mail.gmail.com>
[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:
Show 16 quoted lines
> 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.

Previous: John KeepingNext: Jesse Hopkins
Message 4 of 5 in “determine name of tag used for checkout when multiple tags exist?”
  1. Jesse HopkinsSep 4, 2015
  2. Jacob KellerSep 4, 2015
  3. John KeepingSep 4, 2015
  4. John KeepingSep 4, 2015
  5. Jesse HopkinsSep 5, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.