git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Recovering from a "detached from" HEAD
@ 2019-01-07 16:17 Alyssa Ross
  2019-01-07 19:43 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Alyssa Ross @ 2019-01-07 16:17 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 619 bytes --]

If I detach my head, then use `git subtree add` to generate a commit,
the output from `git status` changes from "detached at SHA" to
"detached from SHA". The sha doesn't change, but HEAD has updated.

I don't understand why `git status` doesn't tell me that I'm
"detached at" the sha of the new commit, but not only that, it seems to
be extremely difficult to get `git status` to reflect my actual HEAD.
`git checkout HEAD` doesn't change it, `git checkout NEWSHA` doesn't
work.

So my question is, what's going on here? Is this intentional behaviour,
or a bug? How should I get my working tree back to a normal state?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Recovering from a "detached from" HEAD
  2019-01-07 16:17 Recovering from a "detached from" HEAD Alyssa Ross
@ 2019-01-07 19:43 ` Junio C Hamano
  2019-01-08 14:19   ` Alyssa Ross
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2019-01-07 19:43 UTC (permalink / raw)
  To: Alyssa Ross; +Cc: git

Alyssa Ross <hi@alyssa.is> writes:

> If I detach my head, then use `git subtree add` to generate a commit,
> the output from `git status` changes from "detached at SHA" to
> "detached from SHA". The sha doesn't change, but HEAD has updated.

This is expected, and there is nothing to "recover from".  Use of
"git subtree add" should be irrelevant (iow, you should get the same
behaviour no matter _how_ you build new commits on the unnamed
branch).

    $ git checkout --detach
    $ git status -uno
    HEAD detached at 9745ede235
    $ git commit --allow-empty -m empty
    [detached HEAD bc9a31f2df] empty
    $ git status -uno
    HEAD detached from 9745ede235

The commit the message shows is meant to indicate where your unnamed
branch diverged at named branches.  Immediately after moving to the
unnamed branch by detaching the HEAD, the message says "at"; the
HEAD is pointing directly at the tip of the then-current branch and
that is where the tip of the unnamed branch is.  You can tell from
that message that you will not lose any commit if you were to check
out a named branch from that state.

After you make a commit on the unnamed branch, you have something to
lose if you were to check out a named branch from that state, as the
detached HEAD is the _only_ thing these new commits you built on top
of the fork point.  Upon seeing "HEAD detached from 9745ede235", you
could do "git log 9745ede235.." and see what you would end up losing
if you were to switch to another branch without saving them first to
a named branch.

> So my question is, what's going on here? Is this intentional behaviour,
> or a bug? How should I get my working tree back to a normal state?

There is nothing abnormal in this state while you are working on an
unnamed branch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Recovering from a "detached from" HEAD
  2019-01-07 19:43 ` Junio C Hamano
@ 2019-01-08 14:19   ` Alyssa Ross
  2019-01-08 14:44     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Alyssa Ross @ 2019-01-08 14:19 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1101 bytes --]

> The commit the message shows is meant to indicate where your unnamed
> branch diverged at named branches.  Immediately after moving to the
> unnamed branch by detaching the HEAD, the message says "at"; the
> HEAD is pointing directly at the tip of the then-current branch and
> that is where the tip of the unnamed branch is.  You can tell from
> that message that you will not lose any commit if you were to check
> out a named branch from that state.
>
> After you make a commit on the unnamed branch, you have something to
> lose if you were to check out a named branch from that state, as the
> detached HEAD is the _only_ thing these new commits you built on top
> of the fork point.  Upon seeing "HEAD detached from 9745ede235", you
> could do "git log 9745ede235.." and see what you would end up losing
> if you were to switch to another branch without saving them first to
> a named branch.

Thank you for the detailed explanation. I was for some reason under the
impression that "git status" would show the current HEAD, rather than
where it was detached. Why I thought that, I don't know.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Recovering from a "detached from" HEAD
  2019-01-08 14:19   ` Alyssa Ross
@ 2019-01-08 14:44     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2019-01-08 14:44 UTC (permalink / raw)
  To: Alyssa Ross; +Cc: git

Alyssa Ross <hi@alyssa.is> writes:

>> The commit the message shows is meant to indicate where your unnamed
>> branch diverged at named branches.  Immediately after moving to the
>> unnamed branch by detaching the HEAD, the message says "at"; the
>> HEAD is pointing directly at the tip of the then-current branch and
>> that is where the tip of the unnamed branch is.  You can tell from
>> that message that you will not lose any commit if you were to check
>> out a named branch from that state.
>>
>> After you make a commit on the unnamed branch, you have something to
>> lose if you were to check out a named branch from that state, as the
>> detached HEAD is the _only_ thing these new commits you built on top
>> of the fork point.  Upon seeing "HEAD detached from 9745ede235", you
>> could do "git log 9745ede235.." and see what you would end up losing
>> if you were to switch to another branch without saving them first to
>> a named branch.
>
> Thank you for the detailed explanation. I was for some reason under the
> impression that "git status" would show the current HEAD, rather than
> where it was detached. Why I thought that, I don't know.

I wrote not from the documentation but from what I remember about
the discussion that led to final phrasing of the message, and I
strongly suspect that your impression is the sign that our docs are
insufficient.  If you can spot where we can improve on, that would
be great.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-08 14:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-07 16:17 Recovering from a "detached from" HEAD Alyssa Ross
2019-01-07 19:43 ` Junio C Hamano
2019-01-08 14:19   ` Alyssa Ross
2019-01-08 14:44     ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).