在一次提交git的途中,出現了一下問題
1.git push origin master后出現
Everything up-to-date
當時以為問題自己點錯了,又重新提交了一次,在 git commit之后出現HEAD detached from 4d1722c錯誤
立即用git status查看,也是這樣的內容,當時網上了教程很不清晰,自己還git checkout master,導致代碼差點丟失
2.具體的做法如下
- git reflog 找到需要恢復的commit ,記下前面的commit id
- git branch temp efa64f5 新建一個名字叫temp的分支,用這個分支代替之前的臨時分支並且擁有想要恢復的commit,efa64f5為要恢復的commit id
- git push origin temp推送到倉庫
- git checkout master切換到主分支
- git merge temp 將temp合並到master
- 保險起見,先git push origin master 推送到倉庫
- 查看是否更新,若更新則git branch -d temp刪除該分支