I am looking for a better method for getting the latest commit's hash in git.
I know git log -1 can show the info of the latest commit and from the info of the latest commit I can use grep and other tools to get the hash.
git log -1
Is there better method supported from git?
Note: a better method is introduced in this QA.
You can use the --format option of git log:
git log -n1 --format=format:"%H"
Here, "%H" means "commit hash".
For explanation and other options of the format string, please check git log manual.