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

Unexpected behavior with :/<text> references

From
William Chargin <wchargin@gmail.com>
Date
Jul 9, 2018, 03:29 UTC
Message-ID
<CAFW+GMBLeLyJjJPaEXkyQ5fJ=L4q4vQ=26wjZ+n07ZvSaTaCUg@mail.gmail.com>
Hello,

I'm experiencing strange behavior with :/<text> references, which seems to be inconsistent with the explanation in the docs on two counts. First, sometimes the matched commit is not the youngest. Second, some commits cannot be found at all, even if they are reachable from HEAD.

Here is a script to reproduce the behavior (Git built from current pu):
    #!/bin/sh
    export GIT_CONFIG_NOSYSTEM=1
    export GIT_ATTR_NOSYSTEM=1
    cd "$(mktemp -d --suffix .gitrepro)"
    git --version
    git init
    git commit -q --allow-empty -m initial
    git commit -q --allow-empty -m foo
    git checkout -q -b early-branch
    git commit -q --allow-empty -m foobar
    git checkout -q --detach
    git commit -q --allow-empty -m foobarbaz
    echo
    echo "The following should all print 'foobarbaz':"
    git show --format=%s ':/foo' --
    git show --format=%s ':/foobar' --
    git show --format=%s ':/foobarbaz' --
    echo
    echo "With an explicit branch:"
    git branch late-branch
    git show --format=%s ':/foo' --
    git show --format=%s ':/foobar' --
    git show --format=%s ':/foobarbaz' --
Here is the output on my machine:
    git version 2.18.0.516.g6fb7f6652
    Initialized empty Git repository in /tmp/tmp.WeCD0QZPIf.gitrepro/.git/
    The following should all print 'foobarbaz':
    foo
    foobar
    fatal: bad revision ':/foobarbaz'
    With an explicit branch:
    foo
    foobarbaz
    foobarbaz

First, the commit with message "foobar" clearly matches the regular expression /foo/ as well as /foobar/, but ":/foo" resolves to an older commit. However, Documentation/revisions.txt indicates that a :/<text> reference should resolve to the _youngest_ matching commit.

Second, the commit with message "foobarbaz" is reachable from HEAD, and yet the regular expression /foobarbaz/ fails to match it. The same documentation indicates that :/<text> references find commits reachable from any ref, and the glossary entry for "ref" states that HEAD is a "special-purpose ref" even though it does not begin with "refs/".

It looks to me like references reachable from `master` are always picked over other references, and that references reachable only from HEAD are not matched at all.

Is the observed behavior intentional? If so, what am I misunderstanding?

Thanks! WC

(for searchability: colon slash text references)
Next: William Chargin
Message 1 of 4 in “Unexpected behavior with :/<text> references”
  1. William CharginJul 9, 2018
  2. William CharginJul 9, 2018
  3. Jeff KingJul 9, 2018
  4. William CharginJul 9, 2018

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.