Total Count of Change Sets for Mercurial and Git
Asked Answered
G

6

6

Is it possible to count the number of Mercurial/Git changesets (commits) with a simple command line with arguments?

Gully answered 21/5, 2013 at 14:40 Comment(0)
R
3

For git:

git log --pretty=oneline | wc -l

will give you the count of all commits on the current branch back to the original commit.

To get the count of all commits on all branches:

git log --pretty=oneline --all | wc -l
Ruder answered 21/5, 2013 at 15:40 Comment(0)
S
14

For mercurial just check the numeric revision id of 'tip' (defined as the highest numbered revision):

$ hg id --num --rev tip
97
Slime answered 21/5, 2013 at 18:29 Comment(3)
That's right. If you want a shellish way to add 1 you'd do $((1 + $(hg id --num --rev tip)))Slime
That result is not necessarily true. Obsolete (thus extinct) changesets count towards that number. The real number of commits is thus equal or smaller than the output of hg id -n -rtip. It's only guaranteed to be equal for a fresh clone.Smock
@planetmaker: I used hg log -r 'ancestors(.)' from this answer in conjunction with a simple --template and wc -w to count the amount of ancestors that a given changeset has. This number is fixed for a changeset as it depends on the changeset's history. Unlike the local revision number it counts only ancestors, not other heads. And it doesn't depend on the order changesets arrived in the repo.Titrant
W
5

I would take a look at churn extension shipped with Mercurial. It lets you count the number of changesets per developer or per time period. It looks like this:

$ hg churn -s -c -f "%Y-%m"
2005-05    208 *****************************                                    
2005-06    341 ***********************************************
2005-07    271 *************************************
...

If you just want to know the number of changesets matching a given revision set, then use hg log and wc like others have suggested:

$ hg log -r "user(geisler) and date('>2010')" --template x | wc -c
735
Weylin answered 21/5, 2013 at 20:5 Comment(0)
R
3

For git:

git log --pretty=oneline | wc -l

will give you the count of all commits on the current branch back to the original commit.

To get the count of all commits on all branches:

git log --pretty=oneline --all | wc -l
Ruder answered 21/5, 2013 at 15:40 Comment(0)
U
2

Here is my quick solution:

  hg log | grep changeset | wc -l

(Of course this only wokrs if nobody writes changeset in their commit messages, etc.)


Explanation:

hg log returns information in this format:

changeset:   232351:06d3053eg093
branch:      default/XXXXXX
bookmark:    hg
tag:         tip
user:        User
date:        Thu Feb 20 10:22:30 2020 +0100
summary:     XXXXXX: cleanup in test

Greping only one of the lines and then counting the lines gives you the count.

Unapproachable answered 22/2, 2020 at 12:40 Comment(0)
W
0

Yes, this question is really old, but here's a more git-native way to get the commit count for git. I'm using git 2.15 currently, but I don't know how long this has been around.

git rev-list --all --count

for a total across all branches, or

git rev-list HEAD --count

for ancestors of HEAD (or any other changeset).

Whimsy answered 17/8, 2018 at 16:53 Comment(0)
T
0

I'm using the following scriptlet to count the amount of hg ancestors that a specific revision has:

hg log -r 'ancestors(.)' --template '1' \
 | wc --bytes

Added in https://hg.pushbx.org/ecm/ldebug/rev/8b6e8611982a with this message:

mak.sh: in revision ID string include amount of ancestors

This number is both fixed for a given changeset whereever it goes and also allows to compare two numbers, assuming they're on the same branch, to one another to figure out which one is "later" or more advanced, so to say.

Although that exact command is from https://hg.pushbx.org/ecm/ldebug/rev/6cbc8bdbb764

This counts the amount of all ancestor changesets in the history up to and including the one listed. (That's the dot . for current working directory parent in the example, you can use another revision specification however.) That means it doesn't matter what other branches may exist in the same repo, unlike the numeric local revision ID.

Titrant answered 6/12, 2022 at 15:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.