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

Re: [PATCH] switch: mention the --detach option when dying due to lack of a branch

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 23, 2022, 23:07 UTC
Message-ID
<xmqqwnhlp4h1.fsf@gitster.g>
In-Reply-To
<20220223073125.640133-1-alexhenrie24@gmail.com>
Alex Henrie <alexhenrie24@gmail.com> writes:
> Users who are accustomed to doing `git checkout <tag>` assume that
> `git switch <tag>` will do the same thing. Inform them of the --detach
> option so they aren't left wondering why `git switch` doesn't work but
> `git checkout` does.
An error message certainly would help over showing
	fatal: a branch is expected, got tag 'abc'

but I have to wonder why we shouldn't DWIM and detach the HEAD at the commit the user wanted to. That would also solve the issue of leaving them wondering why switch is broken and checkout is not, no?

If the advice for detached HEAD state is enabled, then the user will be reminded that they are not on any branch the usual way when the HEAD is detached at the named commit. And if the advice is not enabled, then they will not be helped by this new advise() message we add here.

> +	if (advice_enabled(ADVICE_DETACHED_HEAD))
> +		advise(_("The specified commit is not a local branch.\n"
> +			 "If you want to enter detached head mode, try again with the --detach option."));
> +
"detached HEAD" is a state, and not a mode.
s/enter detached head mode/detach HEAD at the commit/ perhaps.
Thanks.
Previous: Alex HenrieNext: Alex Henrie
Message 2 of 5 in “switch: mention the --detach option when dying due to lack of a branch”
  1. switch: mention the --detach option when dying due to lack of a branchAlex Henrie, Feb 23, 2022
  2. Junio C HamanoFeb 23, 2022
  3. Alex HenrieFeb 23, 2022
  4. Ævar Arnfjörð BjarmasonFeb 23, 2022
  5. Alex HenrieFeb 24, 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.