The easiest way to get the SHA of an arbitrary git object?

I need a git command that simply displays the SHA of an arbitrary object (commit, tree, blob, whatever). Primarily:

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

... etc. It should be the easiest thing in the world, but I cannot figure out how to do it. I don't mind using an alias for the complex, optional git command, but it seems like I just have to skip the very simple U-turn command, which git must be used under the hood all the time.

+5
source share
1 answer

For the purposes that you indicated, yours git shareally git rev-parse.

% git rev-parse HEAD
47753f420d6ec7d84f8705e9acb67693745b4a8b
% git rev-parse origin/pu^:Documentation/RelNotes-1.7.1.txt
9d89fedb36b4d6fa7c8a6a8487cc47b4ca542e3a
+6
source

All Articles