使用Git進行本地提交後,未上傳提交,卻不小心刪除了本地提交或提交所在分支,怎麼辦?????
不要緊!!!!
可以使用git reflog命令來幫助恢復刪除的本地提交!
運行以下命令你就知道怎麼用了!
git stash 清空工作區和暫存區
git pull 同步服務器代碼
git commit –allow-empty -m “this is a test” 進行一次空提交
git reset HEAD^ –hard 刪除剛纔的空提交
git reflog 查看各分支的提交記錄
70cf5fe HEAD@{0}: reset: moving to HEAD^
28d447f HEAD@{1}: commit: this is a test
70cf5fe HEAD@{2}: pull: Fast-forward
git reset 28d447f –hard 恢復到commit號爲28d447f 的提交,亦可使用HEAD@{1}
git log
看this is a test 提交是不是回來了!!