Assume there are three commit, git status:
Commit3: Add test3.c
Commit2: Add test2.c
Commit1: Add test1.c
Simulate the loss of the commit record and execute git reset -- hard head ~ 1. The commit3 file is deleted, and the test3.c file is invisible in the working tree. To restore commit3, use git reflog and git cherry-pick.
$ Git reflog
502dd0f head @ {0}: Head ~ 1: updating head
147b3b5 head @ {1}: commit: test3
502dd0f head @ {2}: commit: Test2
0692c03 head @ {3}: Commit (initial): test1
Head @ {0}: Head ~ 1: updating head
The red bold is the deleted commit3, And the GIT reset -- hard 502dd0f can be used to run the GIT log without this record.Delete the red record and restore cmit3. use git cherry-pick.
$ Git cherry-pick 147b3b5
[Master 02c1e69] test3
0 files changed, 0 insertions (+), 0 deletions (-)
Create mode 100644 test3.c
After running git log, you can see:
Commit3: Add test3.c
Commit2: Add test2.c
Commit1: Add test1.c