How to undo the last local commit using git, which has not been pushed to the repository?

For example following is seen using the git log command. Use -2 option to view last 2 commits:

user@host ~ % git log -2
commit 2 (HEAD -> master)
Author: larry <larry@example.net>
Date:   Wed Jan 27 22:10:03 2021 +0100

   BAD commit. Last commit. It is called 'HEAD'

commit 1 (origin/master)
Author: larry <larry@example.net>
Date:   Wed Jan 27 21:15:37 2020 +0100

   GOOD commit. Second to last  commit. This has the desired state.

Latest commit, commit number 2 is the commit that is not wanted. It should not be pushed into the repository. Commit number 1 has the desired state. This is the version that is wanted.

To restore everything back to the state it was prior to the last commit it is needed to reset to the commit to before HEAD:

Using the git reset --soft if changes made should be kept:

user % git reset --soft HEAD^

Use the --hard option changes to the files are not wanted and should be dropped:

user % git reset --hard HEAD^

Now git log will show that our last commit has been removed. Use again the git log command to view the current state:

user % git log