How to undo (almost) anything with Git
https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/
https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/
checkout, reset, restore, revert, and switch. What do they really do?
Written by torek, etc.
The whole page is useful, especially from 'To add to VonC's answer, and bring into the picture all the relevant commands, in alphabetical order, I will cover:'
I also like -
$git restore -s@ -SW -- <file>
above the aforesaid section.
How to undo and redo in git?
For both undo and redo, use git reflog and git reset --hard head@{n}
You will find n in the result of git reflog.