Re: Head, Branch != Head -> Branch?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tomas,
> In what scenarios would you create a new branch and not check it out?

These are some examples of cases where I want to make but not checkout
a new branch:
1. I've made a backup branch in case I'm about to screw up the one I'm
on and want to be able to get back to the branch's current state.
2. I want a branch at this point because I'm planning on doing working
on multiple, independent features from the same point and don't know
when they'll be merged together, and I can only work on each one a
little at the time. It's nice because I can branch from a point that's
stable.

> Is there a scenario where you would do this in detached head mode?

Someone may want to be in detached mode to check out a bug behavior at
some commit without modifying the code at all, so there's no sense in
making a new branch.

---
> Could HEAD attach itself to a nearby branch whenever a command
> requiring an attached branch is called and HEAD points to a commit
> with only 1 branch attached to it? This would not include commit,
> since it does not require an attached branch and thus would not fail
> on detached mode, this should not break bc because it only affects
> commands that would otherwise throw an error.

If they change their mind once detached, it's simple enough to
reattach by just making a new branch where they're checked out. But if
you don't do that, how is git supposed to select a name? There's no
way to pick a good one other than the current SHA... which is exactly
how you'd place yourself currently.

> Alternatively, a more specific error message could be printed,
> prompting the user to attach their head to the branch on the commit.

There actually IS a very clear prompt to reattach:
"If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>"

Lastly, being in a detached state isn't an error, so I don't see why
an error message needs to be printed. It's quite clear that you're not
attached to any branch in particular, and it's quite clear when you
run git branch what SHA you're on and that you're detached. I as a
user would never want git to try and decide to attach itself to a new
branch, it might make the wrong choice and aggravate me. As it stands
the documentation and resulting text from commands are both quite
clear in my opinion.

mattr94,
I do agree that this is outside a new user's expectation, as Tomas has
stated, because I've taught many people git and this is a common
surprise. However, it's adequately documented and frequently covered
in tutorials. Moreoever, the commands are consistent: checkout checks
out a particular commit/branch, branch creates branches. Perhaps the
documentation could be added removing the newline between note and the
line above, so there's less of a separation between them? That would
do a better job of drawing the reader's eye to the note as being
related. (PS, I only count 4 paragraphs, but maybe I'm looking at the
wrong version?.. sorry if so).

Best,
Josh

On Sun, Dec 15, 2019 at 12:33 AM Joshua Teves <jbtevespro@xxxxxxxxx> wrote:
>
> Tomas,
> > In what scenarios would you create a new branch and not check it out?
>
> These are some examples of cases where I want to make but not checkout a new branch:
> 1. I've made a backup branch in case I'm about to screw up the one I'm on and want to be able to get back to the branch's current state.
> 2. I want a branch at this point because I'm planning on doing working on multiple, independent features from the same point and don't know when they'll be merged together, and I can only work on each one a little at the time. It's nice because I can branch from a point that's stable.
>
> > Is there a scenario where you would do this in detached head mode?
>
> Someone may want to be in detached mode to check out a bug behavior at some commit without modifying the code at all, so there's no sense in making a new branch.
>
> ---
> > Could HEAD attach itself to a nearby branch whenever a command
> > requiring an attached branch is called and HEAD points to a commit
> > with only 1 branch attached to it? This would not include commit,
> > since it does not require an attached branch and thus would not fail
> > on detached mode, this should not break bc because it only affects
> > commands that would otherwise throw an error.
>
> If they change their mind once detached, it's simple enough to reattach by just making a new branch where they're checked out. But if you don't do that, how is git supposed to select a name? There's no way to pick a good one other than the current SHA... which is exactly how you'd place yourself currently.
>
> > Alternatively, a more specific error message could be printed,
> > prompting the user to attach their head to the branch on the commit.
>
> There actually IS a very clear prompt to reattach:
> "If you want to create a new branch to retain commits you create, you may
> do so (now or later) by using -b with the checkout command again. Example:
>
>   git checkout -b <new-branch-name>"
>
> Lastly, being in a detached state isn't an error, so I don't see why an error message needs to be printed. It's quite clear that you're not attached to any branch in particular, and it's quite clear when you run git branch what SHA you're on and that you're detached. I as a user would never want git to try and decide to attach itself to a new branch, it might make the wrong choice and aggravate me. As it stands the documentation and resulting text from commands are both quite clear in my opinion.
>
> mattr94,
> I do agree that this is outside a new user's expectation, as Tomas has stated, because I've taught many people git and this is a common surprise. However, it's adequately documented and frequently covered in tutorials. Moreoever, the commands are consistent: checkout checks out a particular commit/branch, branch creates branches. Perhaps the documentation could be added removing the newline between note and the line above, so there's less of a separation between them? That would do a better job of drawing the reader's eye to the note as being related. (PS, I only count 4 paragraphs, but maybe I'm looking at the wrong version?.. sorry if so).
>
> Best,
> Josh
>
> On Sat, Dec 14, 2019 at 10:40 PM Tomas Zubiri <me@xxxxxxxxxxxxxxx> wrote:
>>
>> It was just a combination of an old gripe I have with expecting git
>> branch to checkout and conflating (HEAD pointing to a commit and
>> branch pointing to a commit) with (HEAD pointing to a branch pointing
>> to a commit).
>>
>> In what scenarios would you create a new branch and not check it out?
>> Is there a scenario where you would do this in detached head mode?
>>
>> ---
>>
>>  Could HEAD attach itself to a nearby branch whenever a command
>> requiring an attached branch is called and HEAD points to a commit
>> with only 1 branch attached to it? This would not include commit,
>> since it does not require an attached branch and thus would not fail
>> on detached mode, this should not break bc because it only affects
>> commands that would otherwise throw an error.
>> Alternatively, a more specific error message could be printed,
>> prompting the user to attach their head to the branch on the commit.
>>
>> Regards.
>> El sáb., 14 de dic. de 2019 a la(s) 19:41, <mattr94@xxxxxxxxx> escribió:
>> >
>> >
>> > After going through the code and thinking about this. I think the unexpected results came from git branch not checking out the branch I created.
>> > I know git checkout -b master would have been the result I wanted. If I were to create another commit with HEAD checked out instead of master, master would not update, only HEAD would.
>> > > I guess the real crime here is that git branch does not checkout the branch created. I don't think I ever wanted to create a branch without checking it out, otherwise I would use git tag.
>> >
>> > The problem with this is that git tag doesn't create a new branch, but rather just a new tag so running something like:
>> >
>> > git tag my-tag
>> > git checkout my-tag
>> > git add .
>> > git commit -m "message"
>> >
>> > wouldn't update my-tag either, you would need to create a new branch for that.  Sometimes I want to create a branch without checking it out, as I'm sure many other users do.  Is it an issue of documentation where maybe the behavior isn't clear? It does specifically say this in the description of git branch, but to be fair it is buried 6 paragraphs in
>> >




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux