What is the command to show the SHA-1 hash of a Git object, such as a commit or tree?
Posted by FrankMl
Last Updated: July 20, 2024
To show the SHA-1 hash of a Git object, such as a commit or tree, you can use the following command:
git rev-parse <object>
Replace <object> with the identifier of the object you want to examine, which can be a commit hash, branch name, or tag name, among other references. For example, to get the SHA-1 hash of the current commit, you would use:
git rev-parse HEAD
If you want to see the SHA-1 hash of a specific tree, you can provide the tree reference (e.g., a branch name):
git rev-parse <branch-name>:<path>
If you just want to see the hash for the tree corresponding to the currently checked-out commit, you can use:
git rev-parse HEAD^{tree}
This will give you the SHA-1 hash for the tree object of the latest commit on the current branch.