Use git show and check for exit status
$ git show -s 97d79ecf6b6 commit 97d79ecf6b6c5cc3c1485eb3c46e12986a978f57 Author: Dave MethvinDate: 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