I am looking for a better method for getting the latest commit’s hash in git.
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.
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 -n1 --format=format:"%H"
Here, “%H” means “commit hash”.