Given a local / remote branch name, how could I get the hash of the commit that this branch points to?
If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .
To search for a hash, just enter at least the first 7 characters in the search box. Then on the results page, click the "Commits" tab to see matching commits (but only on the default branch, usually master ), or the "Issues" tab to see pull requests containing the commit.
Hashes are what enable Git to share data efficiently between repositories. If two files are the same, their hashes are guaranteed to be the same. Similarly, if two commits contain the same files and have the same ancestors, their hashes will be the same as well.
The command git rev-parse
is your friend, e.g.:
$ git rev-parse development 17f2303133734f4b9a9aacfe52209e04ec11aff4
... or for a remote-tracking branch:
$ git rev-parse origin/master da1ec1472c108f52d4256049fe1f674af69e785d
This command is generally very useful, since it can parse any of the ways of specifying branch names in git
, such as:
git rev-parse master~3 git rev-parse HEAD@{2.days.ago}
... etc.
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