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.
Since trees and blobs, like all other objects, are named by the SHA1 hash of their contents, two trees have the same SHA1 name if and only if their contents (including, recursively, the contents of all subdirectories) are identical.
As is well-known, Git has been using SHA-1 to calculate a hash for each commit: For example, files, directories, and revisions are referred to by hash values unlike in other traditional version control systems where files or versions are referred to via sequential numbers.
Blob is an abbreviation for “binary large object”. When we git add a file such as example_file. txt , git creates a blob object containing the contents of the file. Blobs are therefore the git object type for storing files.
A "tree" in Git is an object (a file, really) which contains a list of pointers to blobs or other trees. Each line in the tree object's file contains a pointer (the object's hash) to one such object (tree or blob), while also providing the mode, object type, and a name for the file or directory.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With