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

Re: rev-parse: -- is sometimes a flag and sometimes an arg?

From
THTim Hockin <thockin@google.com>
Date
Aug 21, 2022, 00:31 UTC
Message-ID
<CAO_RewZPXP1EUP90kU6uEQ3_CqqC7yWedjfNd7RaVASFSfrg0Q@mail.gmail.com>
In-Reply-To
<xmqq8rniikrg.fsf@gitster.g>

Thanks. Is there a more friendly way to do what I'm trying to express? Should I just use `rev-list -n1` instead?

On Sat, Aug 20, 2022 at 3:59 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 47 quoted lines
>
> Tim Hockin <thockin@google.com> writes:
>
> > ```
> > $ git rev-parse unknown-tag
> > unknown-tag
> > fatal: ambiguous argument 'unknown-tag': unknown revision or path not
> > in the working tree.
> > Use '--' to separate paths from revisions, like this:
> > 'git <command> [<revision>...] -- [<file>...]'
> > ```
> >
> > OK
> >
> > ```
> > $ git rev-parse unknown-tag --
> > fatal: bad revision 'unknown-tag'
> > ```
> >
> > Much nicer error.  But:
> >
> > ```
> > $ git rev-parse HEAD --
> > 113a928239196d0d9f70671517ce917071ceecf6
> > --
> > ```
> >
> > That's not very nice.  Why is "--" treated as an arg?
> >
> > ```
> > $ git rev-parse HEAD
> > 113a928239196d0d9f70671517ce917071ceecf6
> > ```
> >
> > Looking at rev-parse code it SEEMS to be intentional, but I can't
> > comprehend why.
>
> Because the first function of "rev-parse" (among many others) is to
> be a helper usable in scripted Porcelains to "parse" command line
> arguments, shifting them into revs and "files".  Without options
> like --revs-only, --no-revs, --flags etc., it dumps everything, while
> translating "revs" into raw object names, to its output.  "--" is a
> valid command line option for whatever scripted Porcelain you'd be
> writing using "rev-parse" to help parsing its command line arguments.
>
> So everything we see above is very much working as designed.
>
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 8 in “rev-parse: -- is sometimes a flag and sometimes an arg?”
  1. Tim HockinAug 20, 2022
  2. Junio C HamanoAug 20, 2022
  3. Tim HockinAug 21, 2022
  4. Junio C HamanoAug 21, 2022
  5. Tim HockinAug 21, 2022
  6. Junio C HamanoAug 21, 2022
  7. brian m. carlsonAug 23, 2022
  8. Tim HockinAug 23, 2022

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.