Xem reflog để khôi phục lại 1 commit bất kì
Reflog như cỗ máy thời gian, nó ghi lại toàn bộ những gì bạn đã làm, kể cả khi bạn xóa 1 commit nào đó.
0979a9e HEAD@{1}: reset: moving to HEAD~
4d77eb9 HEAD@{2}: commit: Add UI for data showcase.
0979a9e HEAD@{3}: commit: Finish UAF module, need update xls file normaly
4d3afe9 HEAD@{8}: commit: Finish UFM Module
c1fe83d HEAD@{9}: commit: Add faculty to model
b5d314a HEAD@{10}: commit: Add faculty_code
c528ae5 HEAD@{11}: pull: Fast-forward
...
0979a9e hoặc HEAD@{3} là id của commit Finish UAF module, need update xls file normaly Để khôi phục lại commit đó
git reset --hard 0979a9e
HEAD is now at 0979a9e Finish UAF module, need update xls file normaly
Lỡ tay reset --hard
Tương tự như trên, ta xem lại reflog$ git reset --hard HEAD~
Kết quả sẽ là0979a9e HEAD@{1}: reset: moving to HEAD~
4d77eb9 HEAD@{2}: commit: Add UI for data showcase.
0979a9e HEAD@{3}: commit: Finish UAF module, need update xls file normaly
237e662 HEAD@{4}: commit: Add noti token update in UFM module
2e99cad HEAD@{5}: commit: Add run shell script, fix out of memory
712d37c HEAD@{6}: commit: Fix priority, SGU doesn't have priority value
295779f HEAD@{7}: pull: Fast-forward
....

0979a9e là commit reset HEAD, 4d77eb9 là commit bị mất bạn cần sẽ nhảy đến.
Để khôi phụcgit reset --hard 0979a9e
HEAD is now at 0979a9e Finish UAF module, need update xls file normaly
Lỡ xóa branch
Trong trường hợp bạn lỡ xóa branch bằngbranch -D thì cũng có thể dễ dàng khôi phục như trường hợp mất commit.$ git br -D duyetdev
Deleted branch duyetdev (was 700674f).
Ta xem lại lịch sử bằng reflog$ git reflog
9b48127 HEAD@{0}: checkout: moving from duyetdev to master
788674f HEAD@{1}: reset: moving to 788674f
Trạng thái muốn quay lại là 788674f, vì thế$ git branch develop 788674f
$ git checkout develop
Và chúng ta sẽ quay lại branch vừa bị xóa lúc nãy.
Tôi là Duyệt