Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the hash of branch in Git?

Tags:

git

Given a local / remote branch name, how could I get the hash of the commit that this branch points to?

like image 747
Misha Moroshko Avatar asked Feb 02 '12 10:02

Misha Moroshko


People also ask

How do I view commit hash?

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 .

How do I get git hash from github?

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.

What is the hash in git?

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.


1 Answers

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.

like image 130
Mark Longair Avatar answered Sep 19 '22 07:09

Mark Longair