Is it possible to count the number of Mercurial/Git changesets (commits) with a simple command line with arguments?
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
For mercurial just check the numeric revision id of 'tip' (defined as the highest numbered revision):
$ hg id --num --rev tip
97
hg id -n -rtip
. It's only guaranteed to be equal for a fresh clone. –
Smock 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 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
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
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.
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).
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.
© 2022 - 2024 — McMap. All rights reserved.
$((1 + $(hg id --num --rev tip)))
– Slime