问题:在使用git时,提示 You are in 'detached HEAD' state.(游离状态)
原因:我在某次commit处打了一个tag v1.0,然后我 git checkout v1.0 ,此时 HEAD 会指向这个commit,而没有指向某个分支。这时我做修改后进行了commit操作,git 提示:
Warning: you are leaving 1 commit behind, not connected to any of your branches:
1ef1245 interrationRecord page completed
If you want to keep them by creating a new branch, this may be a good time
to do so with:…
这个commit就不会提交到任何分支上去,如果直接离开切回到某个分支的话,这些修改可能会丢失。但是我没注意,直接选择把代码提交到远程仓库,失败了,之后发现切回了master分支,结果发现做的修改全没了。
其实,上边git已经提示了,如果还想要这次提交的话,可以创建一个新的分支,并说明了本次提交的id:1ef1245
。
解决:
- 基于本次提交创建临时分支:
git branch temp 1ef1245
- 切换到master分支(之前想要提交的分支)并合并代码:
git checkout master
git merge temp
- 提交到远程分支后删除临时分支:
git branch -d temp