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

Re: [PATCH] branch: delete now accepts '-' as branch name

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 17, 2022, 18:41 UTC
Message-ID
<xmqqiltd9vyg.fsf@gitster.g>
In-Reply-To
<CAPig+cR0Ks2bnTRqs3uF4M+3q+n9X6pApBQ9HQTUq=zK5TpuXQ@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
> Perhaps. Perhaps not. I may be misreading Junio's responses in this
> thread, but it didn't seem like he was necessarily opposed to the
> change.

I do not care too much about this issue to expend my political capital on enforcing my preference ;-)

FWIW, my preference in an ideal world would be to limit "-" as a short-hand to go back to previous (i.e. "checkout -"), which can be justified with similarity to "cd -", but do not add any more use. If we could, I would even deprecate "merge -", "rebase -", etc. that can not be justified with similarity to "cd -", but I think we came too far for that.

"-" cannot be used as a universal "the branch we last 'git checkout' out of" notation because some commands and people expect "-" to be something else, like "read from the standard input". The only two reasons this pops up from time to time is because "checkout -" exists and because "@{-N}" notation, which is accepted everywhere uniformly and does not have problems "-" has, is not very well known.

> A documentation update as in [1] would be a good idea, though,
> if resubmitted.

Yeah, [1] talked about both "@{-1}" and "-", but limiting it to the former may make sense. It feels a bit odd that we single out "git branch" and describe "@{-1}" there, when the notation is universally available, though.

    $ git grep -l '@{-' -- Documentation/ :\!Documentation/\*/\*

shows hits only in check-ref-format, checkout, switch, and worktree, but the mention in "revisions.txt" is included in all commands in the "log" family of commands. If we add one to "branch", we should at least teach "@{-1}" to the documentation of merge, rebase, and revert. The hits we see here

    $ git grep -l -B1 '"@{-' \*.c
    builtin/checkout.c
    builtin/merge.c
    builtin/rebase.c
    builtin/revert.c
    builtin/worktree.c
all are about replacing "-" the user typed with "@{-1}".

Continuing the "thinking aloud" a bit, I _think_ this tells us these things:

 * @{-1} has way too many letters to type to be liked by users, who
   won't learn or remember what they do not appreciate (and do not
   blame them---it is a bad notation).
 * @{-<n>} may have been a generalized way that satisfied geeky mind
   while being implemented, but the users only need the "last one"
   and no such generalization.

If it is too late for a more easy-to-type-and-pleasant-to-eyes notation, perhaps "@-", that does not have downsides of "-" or "@{-1}", I have to wonder.

Thanks.
Previous: Eric SunshineNext: Ævar Arnfjörð Bjarmason
Message 7 of 11 in “branch: delete now accepts '-' as branch name”
  1. branch: delete now accepts '-' as branch nameErlend Egeberg Aasland via GitGitGadget, Feb 16, 2022
  2. Junio C HamanoFeb 16, 2022
  3. Eric SunshineFeb 16, 2022
  4. Junio C HamanoFeb 16, 2022
  5. Erlend AaslandFeb 16, 2022
  6. Eric SunshineFeb 17, 2022
  7. Junio C HamanoFeb 17, 2022
  8. Ævar Arnfjörð BjarmasonFeb 21, 2022
  9. Junio C HamanoFeb 21, 2022
  10. Ævar Arnfjörð BjarmasonFeb 21, 2022
  11. Erlend AaslandFeb 22, 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.