threads / discuss / 53689

git switch error message tweak

Subject: git switch error message tweak

## tl;dr

2 messages between Jun 16, 2020 and Jun 17, 2020.

replies: 1people: 2as markdown or json

Ed Avis· Jun 16, 2020, 06:47 UTC · lore

To help those migrating from 'git checkout' to the newer 'git switch' and 'git restore', this error message could be improved:

% git switch baa022666d26a5d40e86c0b6349eb7435033e80a fatal: a branch is expected, got commit 'baa022666d26a5d40e86c0b6349eb7435033e80a'

It could print additionally
To switch to this commit in 'detached HEAD' mode, use --detach.
as long as it was indeed a commit that was given.

I note also that while git checkout prints a spiel about "You are in 'detached HEAD' state", git switch --detach does not.  Was this deliberate, on the assumption that if you pass --detach you know what you are doing?  I think it might be better to honour the advice.detachedHead setting the same way for both checkout and switch.

Thanks for considering this request, and apologies if this is something already discussed and decided.
-- 
Ed Avis <ed.avis@qmaw.com>
Junio C Hamano· Jun 17, 2020, 20:30 UTC · re: Ed Avis · lore

Re: git switch error message tweak

Ed Avis <ed.avis@qmaw.com> writes:
Show 11 quoted lines
> To help those migrating from 'git checkout' to the newer 'git switch'
> and 'git restore', this error message could be improved:
>
> % git switch baa022666d26a5d40e86c0b6349eb7435033e80a
> fatal: a branch is expected, got commit 'baa022666d26a5d40e86c0b6349eb7435033e80a'
>
> It could print additionally
>
> To switch to this commit in 'detached HEAD' mode, use --detach.
>
> as long as it was indeed a commit that was given.
Excellent.
> I note also that while git checkout prints a spiel about "You are in
> 'detached HEAD' state", git switch --detach does not. Was this
> deliberate, on the assumption that if you pass --detach you know what
> you are doing?

I'd say you are correct---one who passes "--detach" knows enough to want to be in the detached HEAD state and knows enough that the state is nothing to be worried about.

← back to recent threads