git rev-parse
git rev-parse [--short] [--abbrev-ref] <rev>
Risk: Safe
What it does
Turns a name like HEAD~2 or main into a full commit id.
When to use it
To check what a revision name points to.
Example
$ git rev-parse HEAD~2Print the full id of the commit two steps back.
$ git rev-parse --short HEADPrint the short id instead.
$ git rev-parse --abbrev-ref HEADPrint the name of your branch.
$ git rev-parse --show-toplevelPrint the top folder of this repo.
Learn it in: Revision syntax · Official docs