在提交git时,报告状态 The Git repository at the following path is in the detached HEAD state,即Git头指针分离状态 ,这篇文章讲解的挺详细的。
事情起因:
执行了这个语句
git checkout <commit id>
然后在不太了解git的情况下提交了代码,提示了 The Git repository at the following path is in the detached HEAD state。
解决:
通过这个命令查看是否在头指针分离状态
git status
确定后可以给这个分离的提交创建一个分支,然后在将这个分支合并到master中,最后再删除这个临时的分支。
通过这个命令给这个提交创建一个临时的分支,这个分支是基于头指针分离下修改提交的commit id创建的
git branch <branchName> <commitId>
合并分支:
git merge temp
最后删除临时分支:
git branch -d temp
提示:
在分离头指针下当执行git checkout到其他分支时,可能会收到下面的警告,提示用户要新创建一个分支来保留做的修改