simplest way to get the SHA of an arbitrary git object?

I want a git command that simply outputs the SHA of an arbitrary object (commit, tree, blob, whatever). Basically:

$ git sha HEAD
7b78f727c91edc7726f3c31113bc7b1509fea163
$ git sha master^:CHANGELOG
0dcc5f003ed89c30a8d0376a29d546c20449fd90

…and so forth. This should be the simplest thing in the world, but I can’t figure out a good way of doing it. I don’t mind using an alias to a complex, option-laden git command, but it seems like I must just be missing a really simple dereference command that git must surely use under the hood all the time.

  • 'git apply' failed with code 1: patch does not apply error in SourceTree on Stage Hunk
  • Squash hundreds of old commits on origin
  • Git Source Control between two networks
  • Canonicalize current Git commit, using it as a reference point for forked repos
  • Move project into subdirectory
  • Merge different issues on github
  • Multiple heroku accounts
  • gitignore with platform specific defines?
  • When importing/creating branch from git project, I get multiple source folders
  • Git clone not working with npm
  • Migrating from git to Perforce
  • git reset --hard seems to ignore .git/info/exclude
  • One Solution collect form web for “simplest way to get the SHA of an arbitrary git object?”

    For the purposes you have given, your git sha is actually git rev-parse.

    % git rev-parse HEAD
    47753f420d6ec7d84f8705e9acb67693745b4a8b
    % git rev-parse origin/pu^:Documentation/RelNotes-1.7.1.txt
    9d89fedb36b4d6fa7c8a6a8487cc47b4ca542e3a
    
    Git Baby is a git and github fan, let's start git clone.