Get the short Git version hash

Get the short Git version hash

Asked on January 10, 2019 in Git.
Add Comment


  • 4 Answer(s)

    Use this:

    git rev-parse --short HEAD
    
    

    By using this command git rev-parse  is  remarkable number of different things in this  documentation

    Answered on January 10, 2019.
    Add Comment

    Here the following below code for –pretty=format:

    git log -1 --pretty=format:%h
    
    
    Answered on January 10, 2019.
    Add Comment

    Try this alternative code for  short Git version hash:

    git log -1 --abbrev-commit
    
    

    Or,

    git log --abbrev-commit
    
    

    Tabulation  the log entries with shorten SHA-1 checksum.

    Answered on January 10, 2019.
    Add Comment

    s there a cleaner way to get the short version hash of HEADfrom Git?

    I want to see the same output as I get from:

     git log -n 1 | head -n 1 | sed -e 's/^commit //' | head -c 8
    

    I originally used this to generate a version string, but this is even better:

    git describe --tags
    

    It will output strings like 0.1.12 (tagged commit) or 0.1.11-5-g0c85fbc (five commits after the tag).

    Answered on February 20, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.