Fix a Git detached head?

前端 未结 23 1730
臣服心动
臣服心动 2020-11-22 05:42

I was doing some work in my repository and noticed a file had local changes. I didn\'t want them anymore so I deleted the file, thinking I can just checkout a fresh copy. I

23条回答
  •  爱一瞬间的悲伤
    2020-11-22 06:23

    Normally HEAD points to a branch. When it is not pointing to a branch instead when it points to a commit hash like 69e51 it means you have a detached HEAD. You need to point it two a branch to fix the issue. You can do two things to fix it.

    1. git checkout other_branch // Not possible when you need the code in that commit hash
    2. create a new branch and point the commit hash to the newly created branch.

    HEAD must point to a branch, not a commit hash is the golden rule.

提交回复
热议问题