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

Re: `git rebase (--no-fork-point) --onto=<newbase> [<upstream> [<branch>]]` leaves HEAD detached and *HEAD not moved when <branch> is exactly `HEAD`

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 3, 2024, 15:38 UTC
Message-ID
<xmqq4j6woih6.fsf@gitster.g>
In-Reply-To
<981c8e52-e51d-4aab-a970-bb41315e02cb@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 11 quoted lines
>> I have a mild suspicion that the "rebase" command might have changed
>> its behaviour since the days back when it was implemented as a shell
>> script, when the "what to rebase" argument is HEAD, as the most
>> natural implementation to do this "optionally first switch to it
>> when the argument is given" in the scripted Porcelain is to actually
>> run "git checkout HEAD", which should be a somewhat noisy no-op.j
>
> It appears to have changed in 0cb06644a5 (rebase [--onto O] A B: omit
> needless checkout, 2008-03-15). That also changed the reflog messages
> written by "git rebase <upstream> <branch>" so that "git checkout
> @{n}" does not see the new branch being checked out.

Thanks for digging. Even if we now know that it was a regression in the early times of the current code, it is way too old to change it now.

Unless we want to do so at a major version bump, but I do not know if this is big enough to worth writing a release note entry for. Users who do want to run a trial rebase of the current branch on a detached HEAD have all been already using HEAD^0 as the <branch> argument and they have been fine without complaints.

Making it consistent in the opposite direction by changinging "git checkout HEAD" to detach HEAD is unthinkable. So what we have is fine, I would think.

Thanks.
Previous: Phillip Wood
Message 6 of 6 in “`git rebase (--no-fork-point) --onto=<newbase> [<upstream> [<branch>]]` leaves HEAD detached and *HEAD not moved when <branch> is exactly `HEAD`”
  1. Han JiangSep 1, 2024
  2. Phillip WoodSep 1, 2024
  3. Junio C HamanoSep 1, 2024
  4. Han JiangSep 1, 2024
  5. Phillip WoodSep 2, 2024
  6. Junio C HamanoSep 3, 2024

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.