分别如果提交了两次git,如
sepolicy$ git log
commit 695ceb9d8726d1faa72eda7dea1feccf4805b606 (HEAD -> master)
Author: kang <xxx.com>
Date: Tue Jan 21 11:21:22 2025 +0800
usb disk ok
commit 3b3ff9f6c7b30370a8a0c2c7f33013995a808641
Author: kang <xxx.com>
Date: Tue Jan 14 17:56:43 2025 +0800
commit
如果通过git reset --hard恢复到第一次提交
git reset --hard 3b3ff9f6c7b30370a8a0c2c7f33013995a808641
sepolicy$ git log --all
commit 3b3ff9f6c7b30370a8a0c2c7f33013995a808641 (HEAD -> master)
Author: kang <xxx.com>
Date: Tue Jan 14 17:56:43 2025 +0800
commit
可以使用 git reflog
sepolicy$ git reflog
3b3ff9f (HEAD -> master) HEAD@{0}: reset: moving to 3b3ff9f6c7b30370a8a0c2c7f33013995a808641
695ceb9 HEAD@{1}: commit: usb disk ok
3b3ff9f (HEAD -> master) HEAD@{2}: reset: moving to HEAD
3b3ff9f (HEAD -> master) HEAD@{3}: commit (initial): commit
然后通过$ git reset --hard 695ceb9恢复