How to find the hash of branch in Git?

前端 未结 3 1419
遇见更好的自我
遇见更好的自我 2020-12-03 00:30

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

3条回答
  •  暖寄归人
    2020-12-03 00:44

    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.

提交回复
热议问题