Get abbrev-commit for git branch, pure

I need to retrieve shortened commit names for specific git branches. These are usually 7-digit hexadecimal numbers, and they are used by some systems (including the Heroku COMMIT_HASH environment variable) to identify a specific commit.

There are several ugly ways to get an abbreviated commit name, including:

$ git log -1 --oneline | awk '{ print $1 }' d4377e3 $ git describe --always --match '' d4377e3 

Is there a cleaner way to get this value?

+4
source share
3 answers

Great question. I believe that I am looking for git-rev-parse , one of the low-level git commands.

 [ jason@star Data]$ git-rev-parse --short github/master 8b81a38 

Also, if you want to get the latest commit in the current branch, just pass HEAD as a parameter.

 [ jason@star Data]$ git-rev-parse --short HEAD 8b81a38 
+8
source

git log --pretty-format can be used:

 git log -1 --pretty=format:%h 
+2
source

I found pimping-out-git-log useful.

+1
source

Source: https://habr.com/ru/post/1338194/


All Articles