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 16, 2022, 19:41 UTC
Message-ID
<xmqqv8xed2f3.fsf@gitster.g>
In-Reply-To
<00720bfb-c7b7-aaf2-e846-19b08d7b9cf4@sunshineco.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 18 quoted lines
> On 2/16/22 11:54 AM, Junio C Hamano wrote:
>> From: "Erlend E. Aasland" <erlend.aasland@innova.no>
>>> This makes it easy to get rid of short-lived branches:
>>>
>>> $ git switch -c experiment
>>> $ git switch -
>>> $ git branch -D -
>> Or you can use @{-1} directly.  Or short-lived experiment can
>> directly be done on HEAD without any branch ;-)
>> Thanks for trying to make Git better.
>
> Patches implementing this behavior for `git branch -D` have been
> submitted previously but were rejected (if I recall correctly) since 
> "delete" is a destructive operation, unlike other cases in which `-`
> is accepted. A relatively recent submission and ensuing discussion is
> at [1].
>
> [1]: https://lore.kernel.org/git/20200501222227.GE41612@syl.local/T/

I think the thread around <vpqh944eof7.fsf@anie.imag.fr> is what you have in mind as the origin of

 * "-" usually stands for "read from standard input" and using it to
   mean "the previous branch" is a source of confusion, and cannot
   be defended with the excuse of "'cd -' is used to go back to
   where we were" when the command is not going back to that branch
   (i.e. not "checkout -" or "switch -").
 * it is doubly dubious to make it easy to type "-" to cause
   something destructive.
 * on the other hand, since "checkout -" already makes "-" as a
   synonym to "@{-1}", not supporting it elsewhere may appear
   inconsistent.

I personally am sympathetic to the first point, but not that sympathetic to the second one. We made it worse since then by accepting "merge -", which is not about going back, though.

Previous: Eric SunshineNext: Erlend Aasland
Message 4 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.