0

This happens often in my work recently. For example, I was in the master branch, and I want to go back to a specific commit that I see from the 'git log' command. After I check out that previsou commit (for example, 6695724994), if I do 'git branch', I see this message.

ckim@ckim-ubuntu:~/prj/some/dir$ git branch
* (HEAD detached at 6695724994)
  master

I thought 'git log' shows only commit in current branch, so I went to that previous commit, but why am I end up in a detached commit? What is the case?

4
  • Did you rebase your master branch?
    – Pieterjan
    Commented Feb 25, 2023 at 10:30
  • @Pieterjan I didn't. I have done this thing several times in the past. I know some branches have been made since couple of months and it is related to that I guess.
    – Chan Kim
    Commented Feb 25, 2023 at 15:19
  • Although the duplicate answers why you ended up detached, it may not help you understand what to do instead of checking out the previous commit. If you simply wanted to view the log of that commit, then you can do that with git log <commit-id> without needing to check it out first. Also, if the previous commit is still on your current branch, just looking at your current branch may be good enough, because you can view the current branch log and ignore the first commit with your eyes- the rest will be the same. You can also do git log HEAD~1 if the desired commit is on your branch.
    – TTT
    Commented Feb 25, 2023 at 20:26

0

Browse other questions tagged or ask your own question.