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

Re: ':/<oneline prefix>' notation doesn't support full file syntax

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 3, 2008, 21:26 UTC
Message-ID
<7v7ic2zmjp.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<56b7f5510807031127j10e33f3bl516180f7a9b5b5db@mail.gmail.com>
"Dana How" <danahow@gmail.com> writes:
Show 5 quoted lines
> I was surprised to see Dscho advocating removing this feature altogether.
> Others proposed other command sequences which avoided :/ .
> If :/ is now going to be extended and thus perhaps more likely to
> appear in scripts,
> is now the time to change it to ? which has no other special meaning to git?

There are number of problems with ":/" notation, but my biggest gripe is that it is only slightly better than "give back a random commit". You cannot even tell it to "dig from these branch tips, look for the first one that talks about this text".

As Dscho mentioned, --grep works much better and instead of saying:
    $ git diff ':/send-email' HEAD
we can say:
    $ git diff \
      $(git log --pretty=format:%H -1 --grep=send-email master next) HEAD

The error behaviour is somewhat different between the two, though. When you misspell what to grep, the command substitution will give empty and you would get an unexpected result. Being built-in, ':/' syntax can say "I do not find anything that match" fairly easily, and the command substitution version has to say something ugly like:

    $ git diff \
        $(
            x=$(git log --pretty=format:%H -1 --grep=send-email master next)
            case "$x" in
            ('') echo 0000000000000000000000000000000000000000 ;;
            (?) echo $x ;; esac
        ) HEAD
to get a similar effect.

But the point is that you can extend it easily with the :path suffix if you wanted to:

    $ git show \
        $(git log --pretty=format:%H -1 --grep=send-email):git-send-email.perl

You can even alias "log --pretty=format:%H -1" if you wanted to, and use revision limiter other than --grep, like this:

    (in .git/config)
	[alias]
        	pick = log --pretty=format:%H -1
    $ git diff --stat $(git pick -- Documentation)^
    $ git blame $(git pick pu -- remote.c) remote.c

So in short, ':/' is limited (cannot be suffixed with :path, cannot be told to dig down from named revs, etc.) but you can do what ':/' cannot do fairly easily with command substitution.

However, $(git pick --all --grep=something), without suffixed modifiers such as ~$N and :$path, may still be common enough that it might deserve a short-hand ':/' (and that is why we have it).

If people do not find that short-hand useful, I am not strongly opposed to the idea of dropping it. I personally find the notation not very useful cute hack anyway ;-).

Previous: Dana HowNext: Johannes Schindelin
Message 6 of 9 in “':/<oneline prefix>' notation doesn't support full file syntax”
  1. Eric RaibleJul 3, 2008
  2. Junio C HamanoJul 3, 2008
  3. Eric RaibleJul 3, 2008
  4. Johannes SchindelinJul 3, 2008
  5. Dana HowJul 3, 2008
  6. Junio C HamanoJul 3, 2008
  7. Johannes SchindelinJul 4, 2008
  8. Johannes SchindelinJul 4, 2008
  9. Jeff KingJul 3, 2008

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.