Command to get latest Git commit hash from a branch

前端 未结 6 818
春和景丽
春和景丽 2021-01-30 04:39

How can I check with the command line the latest commit hash of a particular Git branch?

6条回答
  •  生来不讨喜
    2021-01-30 05:26

    git log -n 1 [branch_name]
    

    branch_name (may be remote or local branch) is optional. Without branch_name, it will show the latest commit on the current branch.

    For example:

    git log -n 1
    git log -n 1 origin/master
    git log -n 1 some_local_branch
    
    git log -n 1 --pretty=format:"%H"  #To get only hash value of commit
    

提交回复
热议问题