Search code examples
mercurial

Find out number of commits given two commit hashes


In a mercurial repository, how can I count the number of commits between two hashes?

For example, if the tree is like

A
|
B
|
C
|
D
|
E
|
F

How can I find out the number of commits between A and F? In this example, it would be 4.


Solution

  • You could do something like this to list all the commits:

    hg log --rev "1500::1550" --template "{rev} "
    

    then pipe it to a word count tool.

    hg log --rev "1500::1550" --template "{rev} " | wc
    

    one could use "children(1500)::p1(1550)" to only get the inner changesets, but it's safer to just subtract 2 from the final result. That way one doesn't have to care about end changeset having multiple parents.

    Updated based on comment.