Why did my Git repo enter a detached HEAD state?

后端 未结 9 2628
渐次进展
渐次进展 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:04

    I reproduced this just now by accident:

    1. lists the remote branches

      git branch -r
            origin/Feature/f1234
            origin/master
      
    2. I want to checkout one locally, so I cut paste:

      git checkout origin/Feature/f1234
      
    3. Presto! Detached HEAD state

      You are in 'detached HEAD' state. [...])
      

    Solution #1:

    Do not include origin/ at the front of my branch spec when checking it out:

    git checkout Feature/f1234
    

    Solution #2:

    Add -b parameter which creates a local branch from the remote

    git checkout -b origin/Feature/f1234 or

    git checkout -b Feature/f1234 it will fall back to origin automatically

提交回复
热议问题