Re: Bug: "git checkout -b" should be allowed in empty repo
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Feb 6, 2012, 08:59 UTC
- Message-ID
- <4F2F9661.2020606@alum.mit.edu>
- In-Reply-To
- <7vk440a5qw.fsf@alter.siamese.dyndns.org>
On 02/06/2012 06:30 AM, Junio C Hamano wrote:
Show 27 quoted lines
> Jeff King <peff@peff.net> writes: > >> Sure, that's one way to do it. But I don't see any point in not allowing >> "git checkout -b" to be another way of doing it. Is there some other use >> case for "git checkout -b" from an unborn branch? Or is there some >> harmful outcome that can come from doing so that we need to be >> protecting against? Am I missing something? > > Mostly because it is wrong at the conceptual level to do so. > > git checkout -b foo > > is a short-hand for > > git checkout -b foo HEAD > > which is a short-hand for > > git branch foo HEAD && > git checkout foo > > But the last one has no chance of working if you think about it, because > "git branch foo $start" is a way to start a branch at $start and you need > to have something to point at with refs/heads/foo. > > So we are breaking the equivalence between these three only when HEAD > points at an unborn branch.
You are thinking too much like a developer and not like a user. For a user,
git checkout -b foo
is a short-hand for
"create and check out a branch at my current state"
and the interpretation of what that means when I am on an unborn branch seems unambiguous.
Michael
-- Michael Haggerty mhagger@alum.mit.edu http://softwareswirl.blogspot.com/