git 本地提交未推送 不小心遷出、刪除後 的找回方法!

使用Git進行本地提交後,未上傳提交,卻不小心刪除了本地提交或提交所在分支,怎麼辦?????

不要緊!!!!

可以使用git reflog命令來幫助恢復刪除的本地提交!

運行以下命令你就知道怎麼用了!

  1. git stash 清空工作區和暫存區

  2. git pull 同步服務器代碼

  3. git commit –allow-empty -m “this is a test” 進行一次空提交

  4. git reset HEAD^ –hard 刪除剛纔的空提交

  5. git reflog 查看各分支的提交記錄

70cf5fe HEAD@{0}: reset: moving to HEAD^
28d447f HEAD@{1}: commit: this is a test
70cf5fe HEAD@{2}: pull: Fast-forward
  1. git reset 28d447f –hard 恢復到commit號爲28d447f 的提交,亦可使用HEAD@{1}

  2. git log

看this is a test 提交是不是回來了!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章