Why did my Git repo enter a detached HEAD state?

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

    The other way to get in a git detached head state is to try to commit to a remote branch. Something like:

    git fetch
    git checkout origin/foo
    vi bar
    git commit -a -m 'changed bar'
    

    Note that if you do this, any further attempt to checkout origin/foo will drop you back into a detached head state!

    The solution is to create your own local foo branch that tracks origin/foo, then optionally push.

    This probably has nothing to do with your original problem, but this page is high on the google hits for "git detached head" and this scenario is severely under-documented.

提交回复
热议问题