hfossli
hfossli

Reputation: 22972

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).

Upvotes: 0

Views: 1182

Answers (1)

hfossli
hfossli

Reputation: 22972

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 e.g.

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 e.g.

e5c303d47afb7c3a98bc138049024d24924e6a9b Minor code fixes

Upvotes: 2

Related Questions