Why did my Git repo enter a detached HEAD state?

后端 未结 9 2630
渐次进展
渐次进展 2020-11-21 04:36

I ended up with a detached head today, the same problem as described in: git push says everything up-to-date even though I have local changes

As far as I know I didn

9条回答
  •  执念已碎
    2020-11-21 05:11

    A simple accidental way is to do a git checkout head as a typo of HEAD.

    Try this:

    git init
    touch Readme.md
    git add Readme.md
    git commit
    git checkout head
    

    which gives

    Note: checking out 'head'.
    
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:
    
      git checkout -b 
    
    HEAD is now at 9354043... Readme
    

提交回复
热议问题