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

Re: Git alias syntax help

From
Jeff King <peff@peff.net>
Date
Jan 15, 2020, 18:13 UTC
Message-ID
<20200115181351.GB4081287@coredump.intra.peff.net>
In-Reply-To
<CAHMHMxVajKxjBweG=mps0gLwE1o8M69DvPb1iUQYgLXx0VO5AA@mail.gmail.com>
On Wed, Jan 15, 2020 at 01:13:17AM +0200, Σταύρος Ντέντος wrote:
Show 8 quoted lines
> > > new = "!f() { : git log ; git log \"${1}@{1}..${1}@{0}\" \"$@\" ; } ; f"
> > > new = !f() { : git log ; git log "${1}@{1}..${1}@{0}" "$@" ; } ; f
> >
> > Only the first one is correct. In addition to the quotes in the second
> > one being eaten by the config parser, the unquoted semicolon starts a
> > comment.
> 
> Could somehow the latter "become" the correct option?

Unfortunately not without breaking compatibility of existing config files.

Show 5 quoted lines
> Especially in the case of `!sh`:
> 1) You need to quote everything after `=` sign ("forced" double quotes), then
> 2) `sh -c` needs another set (singles are most safe here, I think), and
> 3) If, for some reason, you need to quote further ("$@" would be a
> common suspect usually)

Yes, the quoting can get pretty hairy. If your command is complicated, I suggest writing it as a separate script and dropping it into your $PATH as git-new. Then "git new" will run it automatically (and it's not even any less efficient; it still ends up with a single shell invocation).

> Thank you very much for a complete explaination of all of this .
> 
> Can some of this be documented somewhere?
> Are they somewhere and I missed them?

I think the config syntax around quoting is described in "git help config" (see the section Syntax). The shell parts seem out of scope for Git's manpages themselves, though it sounds like maybe some examples you found could stand to be fixed (and/or to call out the subtlety).

Show 9 quoted lines
> If nothing more, a link to this e-mail chain either on the wiki (if
> https://git.wiki.kernel.org/index.php/Aliases is an official page) or
> on git-alias help (here
> https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases or in some
> "advanced" section, which I cannot find)
> 
> If https://git.wiki.kernel.org/index.php/Aliases is an official page,
> then: was this written for an earlier version?
> Could it also be updated?

I think both of the issues you mentioned have always been true. That wiki is open to editing by the world, so it's possible that somebody just added bad examples (and fixes would be welcome).

I don't know the book content very well. Looking at the page you linked, I don't think it says anything _wrong_, but it definitely doesn't discuss more advanced alias usage. I suspect that would be a welcome addition; they take contributions at https://github.com/progit/progit2.

-Peff
Previous: Σταύρος ΝτέντοςNext: Philip Oakley
Message 4 of 5 in “Git alias syntax help”
  1. Σταύρος ΝτέντοςJan 14, 2020
  2. Jeff KingJan 14, 2020
  3. Σταύρος ΝτέντοςJan 14, 2020
  4. Jeff KingJan 15, 2020
  5. Philip OakleyMar 28, 2020

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.