[martin@fc17 git_study]$ git log--oneline 83e7d89 add lineb in readme <== this commit will be reset hardly 4fd6367 add line1 in readme bfd590e touch readme
1 2 3 4 5
[martin@fc17 git_study]$ git reset HEAD^ --hard HEAD is now at 4fd6367 add line1 in readme [martin@fc17 git_study]$ git log--oneline 4fd6367 add line1 in readme bfd590e touch readme
1 2 3
[martin@fc17 git_study]$ cat readme linea 通过git reflog 我们可以得到误删除的commit对应的ID
0.1.1. git reflog
1 2 3 4 5
[martin@fc17 git_study]$ git reflog 4fd6367 HEAD@{0}: reset: moving to HEAD^ 83e7d89 HEAD@{1}: commit: add lineb in readme 4fd6367 HEAD@{2}: commit: add line1 in readme bfd590e HEAD@{3}: commit (initial): touch readme
[martin@fc17 git_study]$ git checkout -b try_recover 83e7d89 Switched to a new branch ‘try_recover’ [martin@fc17 git_study]$ git log —oneline 83e7d89 add lineb in readme 4fd6367 add line1 in readme bfd590e touch readm [martin@fc17 git_study]$ cat readme linea line b