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

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

From
Han Jiang <jhcarl0814@gmail.com>
Date
Sep 1, 2024, 11:02 UTC
Message-ID
<CANrWfmSY1F4UB2QSjN8XKY7Kwx6FL8SOrz_OadZ4u8XYDpZfBg@mail.gmail.com>

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

cd '/'; cd '/'; rm --force --recursive -- './test_git'; mkdir "$_"; cd "$_"; mkdir --parents -- './server' './client'; git -C './server' init --bare './repo.git' echo '1' >'./file'; git --git-dir='./server/repo.git' --work-tree='.' add './file'; git --git-dir='./server/repo.git' --work-tree='.' commit -m "$((++number))" echo '2' >'./file'; git --git-dir='./server/repo.git' --work-tree='.' add './file'; git --git-dir='./server/repo.git' --work-tree='.' commit -m "$((++number))" git -C './server/repo.git' log --graph --all --patch

git -C './client' clone '../server/repo.git' './repo' branch_default_path="$(git -C './client/repo' symbolic-ref HEAD)" branch_default_name="${branch_default_path#'refs/heads/'}" echo '3' >'./client/repo/file'; git -C './client/repo' add './file'; git -C './client/repo' commit -m "$((++number))" git -C './client/repo' log --graph --all --patch

git -C './server/repo.git' reset --soft HEAD~1 echo '4' >'./file'; git --git-dir='./server/repo.git' --work-tree='.' add './file'; git --git-dir='./server/repo.git' --work-tree='.' commit -m "$((++number))" git -C './server/repo.git' log --graph --all --patch

git -C './client/repo' fetch --all git -C './client/repo' log --graph --all --patch 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 -C './client/repo' log --graph --all --patch echo '5' >'./client/repo/file'; git -C './client/repo' add './file'; git -C './client/repo' -c 'core.editor=:' rebase --continue git -C './client/repo' log --graph --all --patch git -C './client/repo' checkout -B "$branch_default_name" git -C './client/repo' log --graph --all --patch

What did you expect to happen? (Expected behavior)

HEAD points to GIT_DEFAULT_BRANCH and GIT_DEFAULT_BRANCH points to tip of origin's GIT_DEFAULT_BRANCH when rebase completes.

What happened instead? (Actual behavior)

HEAD is detached and *HEAD is not moved when rebase completes, so `git checkout -B` is needed.

What's different between what you expected and what actually happened?
Anything else you want to add:

Replacing `HEAD` with branch name (`"$(git -C './client/repo' branch --show-current)"`) works around the problem. cd '/'; cd '/'; rm --force --recursive -- './test_git'; mkdir "$_"; cd "$_"; mkdir --parents -- './server' './client'; git -C './server' init --bare './repo.git' echo '1' >'./file'; git --git-dir='./server/repo.git' --work-tree='.' add './file'; git --git-dir='./server/repo.git' --work-tree='.' commit -m "$((++number))" echo '2' >'./file'; git --git-dir='./server/repo.git' --work-tree='.' add './file'; git --git-dir='./server/repo.git' --work-tree='.' commit -m "$((++number))" git -C './server/repo.git' log --graph --all --patch

git -C './client' clone '../server/repo.git' './repo' echo '3' >'./client/repo/file'; git -C './client/repo' add './file'; git -C './client/repo' commit -m "$((++number))" git -C './client/repo' log --graph --all --patch

git -C './server/repo.git' reset --soft HEAD~1 echo '4' >'./file'; git --git-dir='./server/repo.git' --work-tree='.' add './file'; git --git-dir='./server/repo.git' --work-tree='.' commit -m "$((++number))" git -C './server/repo.git' log --graph --all --patch

git -C './client/repo' fetch --all git -C './client/repo' log --graph --all --patch git -C './client/repo' -c 'core.editor=cat' rebase --onto=HEAD@{upstream} --interactive "$(git -C './client/repo' merge-base --fork-point HEAD@{upstream} HEAD)" "$(git -C './client/repo' branch --show-current)" git -C './client/repo' log --graph --all --patch echo '5' >'./client/repo/file'; git -C './client/repo' add './file'; git -C './client/repo' -c 'core.editor=:' rebase --continue git -C './client/repo' log --graph --all --patch

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info]
git version:
git version 2.46.0.windows.1
cpu: x86_64
built from commit: 2e6a859ffc0471f60f79c1256f766042b0d5d17d
sizeof-long: 4
sizeof-size_t: 8
shell-path: D:/git-sdk-64-build-installers/usr/bin/sh
feature: fsmonitor--daemon
libcurl: 8.9.0
OpenSSL: OpenSSL 3.2.2 4 Jun 2024
zlib: 1.3.1
uname: Windows 10.0 22631
compiler info: gnuc: 14.1
libc info: no libc information available
$SHELL (typically, interactive shell): C:\Program Files\Git\usr\bin\bash.exe

[Enabled Hooks] not run from a git repository - no hooks to show

Next: Phillip Wood
Message 1 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.