简体   繁体   中英

How to find git commit number on branch/tag and how to find commit id by number?

How can I find the total number of commits on a branch?

(This is usefull when having setting versionnumber on apps etc)


How can I reverse that number to find a commit id?

(This is usefull when you need to debug an app with versionnumber same as commit number).

Find number of commits on branch or tag (leave blank if current branch is desired):

$ git log <branch/tag/blank> --pretty=oneline | wc -l 

Will output eg

5164

Find commit id by commit number (replace 5614 with your commit number)

$ git log <branch/tag/blank> --pretty=oneline --reverse | sed -n 5614p

Will output eg

e5c303d47afb7c3a98bc138049024d24924e6a9b Minor code fixes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM