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
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Sep 1, 2024, 15:26 UTC
Message-ID
<61a4fcc1-1dd8-48a4-a1d4-0201232c9b26@gmail.com>
In-Reply-To
<CANrWfmSY1F4UB2QSjN8XKY7Kwx6FL8SOrz_OadZ4u8XYDpZfBg@mail.gmail.com>
On 01/09/2024 12:02, Han Jiang wrote:
> What did you do before the bug happened? (Steps to reproduce your issue)
> git -C './client/repo' -c 'core.editor=cat' rebase
> --onto=HEAD@{upstream} --interactive "$(git -C './client/repo'
> merge-base --fork-point HEAD@{upstream} HEAD)" HEAD

"git rebase <upstream> <branch>" is designed to switch to a different branch before rebasing it. If you do not want to switch branches you should use "git rebase <upstream>". "<branch>" is expected to be a branch name, not a symbolic ref to the branch like "HEAD".

> Replacing `HEAD` with branch name (`"$(git -C './client/repo' branch
> --show-current)"`) works around the problem.
This is working as expected.

"git checkout HEAD" is a no-op so "git rebase <upstream> HEAD" is behaving differently to "git checkout HEAD && git rebase <upstream>". We could look at changing that but it would be a breaking change for anyone relying on the current behavior to detach HEAD before rebasing.

Best Wishes
Phillip
Previous: Han JiangNext: Junio C Hamano
Message 2 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.