0

My history was

P --> A --> revert_A --> B

I decided to drop revert_A and squash A and B to have

P --> A_squash_B

I run git rebase -i, drop revert_A, squash B. The history becomes what I wanted, but with this message

$ git rebase -i
[detached HEAD 4cc03a1] check also if error log has been written
 Date: Wed Jan 22 11:44:25 2020 +0100
 2 files changed, 29 insertions(+), 3 deletions(-)
Successfully rebased and updated refs/heads/new_branch.

The 4cc03a1 is really the hash of my A_squash_B, and it is not detached as it is referenced by my_branch.

What does git mean by [detached HEAD 4cc03a1]?

AlexTP
  • 213
  • 1
  • 3
  • 6
  • 1
    You were on a detached head before you started your rebase operation. (You did `git checkout B` instead of `git checkout my_branch`.) To fix this, point your branch to the new commit with `git checkout -B my_branch` – David Sugar Jan 22 '20 at 15:12
  • @DavidSugar maybe I don't get what you said, but the changeset `B` is the top of `my_branch` before and after rebasing. – AlexTP Jan 22 '20 at 16:28
  • "detached head" means you are not on a branch. If you do 'git checkout ' you will have a detached head. If you do 'git checkout ' you will not have a detached head. If you have a detached head, you can "fix" it by creating a branch for that head with `git checkout -B ` – David Sugar Jan 23 '20 at 14:12
  • if your detached head is also the tip of a branch, you can just do `git checkout `. The point is you must use your branch name in the `git checkout` command to be on that branch and not have a detached head. If you do `git checkout `, even if that commit is the tip of a branch, you will be in a detached head state. – David Sugar Jan 23 '20 at 14:17
  • @DavidSugar thanks, but I did not `git checkout` anything, only `git rebase -i`. I know how to fix the detached HEAD issue, just want to know why after `git rebase -i`, a warning "detached HEAD" appeared. Should I understand that my git CLI did include checkout as it should not??? I am using git 2.7.4. – AlexTP Jan 23 '20 at 15:36
  • If you were not in a detached head state before the rebase, you should not be in one after a successful rebase. If that happened, I do not know why. – David Sugar Jan 23 '20 at 16:00
  • "Successfully rebased and updated refs/heads/new_branch" means you are on branch `new_branch`. Everything should be fine, shouldn't it? – knittl Oct 21 '22 at 15:53

0 Answers0