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

Re: Restoring detached HEADs after Git operations

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 19, 2017, 17:55 UTC
Message-ID
<xmqqefufuakk.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<CAGZ79kY0gwk7KRY2iAVTXPBjPzx+mkciVWRR2z2cDgiBjQ2uuw@mail.gmail.com>
Stefan Beller <sbeller@google.com> writes:
Show 24 quoted lines
> On Mon, Jun 19, 2017 at 2:52 AM, Patrick Lehmann
> <Patrick.Lehmann@plc2.de> wrote:
>> Hello Lars,
>>
>> for your questions:
>>> If there are multiple branches with the same hash then your script would pick the first one. Can you imagine a situation where this would be a problem?
>>
>> I can't think of a good solution to resolve it automatically. Maybe a script could print that there are multiple possibilities and it choose the first branch in the list.
>>
>>
>>> Plus, you are looking only at local branches. Wouldn't it make sense to look at remote branches, too?
>>
>> This is also related to restoring tags. If we go this way, we should have this priority list:
>> - local branches
>> - remote branches
>
> For remote branches you would create a local branch of the same name
> (if such a branch would not exist, possibly setting it up to track that remote
> branch)?
>
>> - tags
>
> as said in the other email and similar to remote branches, we'd not want to have
> HEAD pointing to them directly but somehow have a local branch.

Let's step back a bit. We detach the HEAD for a good reason, no? Why is it a good idea to move them back on to a branch picked among multiple ones that all happen to be pointing at the same commit?

The user may build on a history of a submodule, and then may push the result out to a particular branch at the other side; that is when being on a named branch in the submodule becomes useful, but even then I do not think randomly picking one branch and be on it is a good thing to do.

I would understand the workflow would go more like so:
 - You do something at the superproject (e.g. create a new branch X
   from an existing commit and check it out), which results in
   submodules' HEADs getting detached at the commits bound to the
   superproject's tree.
 - Because you want to make changes to both submodules and the
   superproject in a consistent way, you'd want to commit changes to
   all of these repositories and the push the result out in an
   atomic way.
 - Hence you tell "Hey, Git, I want all the submodules that I
   modified to be on branch X" from the superproject.
   - This may succeed in a submodule where X is a new name, or the
     current tip of branch X is an ancestor of the detached HEAD.
   - This may fail in a submodule where there is branch X that does
     not want to move to the detached HEAD's state.  In this latter
     case, the user needs to deal with the situation (perhaps the
     old X is expendable; perhaps the HEAD's commit may need to be
     merged to old X; perhaps there are other cases).
though.
Previous: Patrick LehmannNext: Stefan Beller
Message 10 of 14 in “Restoring detached HEADs after Git operations”
  1. Patrick LehmannJun 19, 2017
  2. Lars SchneiderJun 19, 2017
  3. AW: Restoring detached HEADs after Git operationsPatrick Lehmann, Jun 19, 2017
  4. Stefan BellerJun 19, 2017
  5. AW: Restoring detached HEADs after Git operationsPatrick Lehmann, Jun 19, 2017
  6. Stefan BellerJun 19, 2017
  7. AW: Restoring detached HEADs after Git operationsPatrick Lehmann, Jun 19, 2017
  8. Stefan BellerJun 19, 2017
  9. AW: Restoring detached HEADs after Git operationsPatrick Lehmann, Jun 19, 2017
  10. Junio C HamanoJun 19, 2017
  11. Stefan BellerJun 19, 2017
  12. Stefan BellerJun 19, 2017
  13. Jeff KingJun 19, 2017
  14. Ævar Arnfjörð BjarmasonJun 19, 2017

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.