Contents

Count number of character from git history

Sometime I want to count the number of word in text for each git commit history.


Solution (TBD)

I tweaked a command suggested in Stackoverflow command works though I need to check the accuracy in counting Japanese language though.

1
2
3
4
5
for commit in `git rev-list --all`;
do
    git log -n 1 --pretty="%ad %H" $commit;
    git archive $commit | tar -x -O | wc -c;
done

Output:

1
2
3
4
5
6
7
8
9
Mon Nov 15 07:39:26 2021 +0900 8a4dea649d161ad7873eea87f1cc175c47663c36
  152423
Sun Nov 14 07:31:44 2021 +0900 086103e3f01ace7d3801b44cfbd4d533f1f8d915
  144934
Fri Nov 12 10:29:43 2021 +0900 aa69a115dc5f12d7da498a54d37a087643e6ea5a
  132158
Thu Nov 11 07:38:46 2021 +0900 81dbb815ac542e14ee177ef768a25c8b541d1534
  122664
...

Display commit message

1
2
3
4
5
for commit in `git rev-list --all`;
do
    git log -n 1 --pretty="%ad %h %s" $commit;
    git archive $commit | tar -x -O | wc -c;
done

Output:

1
2
3
4
5
6
7
Wed Nov 17 10:00:15 2021 +0900 771e2de Update: 2.txt
  154148
Tue Nov 16 12:16:36 2021 +0900 7519094 Update: 1.txt for v0.2
  153698
Mon Nov 15 07:39:26 2021 +0900 8a4dea6 update: 5.txt
  152423
...

References