How to get the latest commit's hash in git?

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.

Is there better method supported from git?

asked Oct 7, 2015 by anonymous

1 Answer

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.

answered Oct 7, 2015 by Eric Z Ma (44,280 points)
edited Jan 20, 2016 by Eric Z Ma
How to test whether the git repository is dirty? asked Oct 7, 2015 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...