rev-parse 1) is a command line tool that permits to parse the output and output a single value.
For a commit
git rev-parse commitHash^{tree}