Git – Check if a hash is valid

Use git show and check for exit status

$ git show -s 97d79ecf6b6
commit 97d79ecf6b6c5cc3c1485eb3c46e12986a978f57
Author: Dave Methvin 
Date:   Mon Nov 9 17:49:01 2015 -0500

    Dimensions: Empty sets should return undefined
    
    Ref gh-2319
    Closes gh-2701
echo $?
0

Use git cat-file and check for exit status

$ git cat-file commit 97d79ecf6
$ echo $?
0
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments