Can use to checkout files, branches or commits. Latter useful for debugging, viewing how how something worked in previous commit. Second method preferred if you are going to work on it as opposed to just viewing.
[checkout specific commit. Puts in detached HEAD state ok for viewing]
git log --oneline
git checkout <commit-id>
[if want to work to on it check it out to a branch restores HEAD]
git checkout -b <branch-name>
OR
git switch -c <branch-name>
[or to undo the commit checkout and move back to previous branch]
git checkout -
[undo unstaged i.e. Working Tree changes to specified file]
git checkout HEAD <file-name>
[restores file to state of commit specified by head-ref, undoing changes made in all subsequent commits]
git checkout <head-ref> <file-name>
[example: git checkout HEAD~2 myclass.java
]
git commit -m <commit-message> <path-filename>
https://www.atlassian.com/git/tutorials/using-branches/git-checkout