itsmichaelwang
itsmichaelwang

Reputation: 2328

How to get the number of commits on a file from all authors cumulatively

In other words, what git log --follow <file> does, but for all authors together.

For example, if "contributor1" commits to a file 5 times, and I do it 3, the result should be 8 for that file.

Upvotes: 0

Views: 104

Answers (2)

Wolf
Wolf

Reputation: 4452

You can find the total number of commits to a given file, even through renames, by combining git log with wc:

git log --follow --oneline -- filename | wc -l

Upvotes: 1

Sven Marnach
Sven Marnach

Reputation: 601471

One option to get the number of commits for each file would be

git log --format=format: --name-only | sort | uniq -c

This lists the files that were changed in each commit, then groups by file name and counts the occurrences.

If you just want to know the number of commits for a single file, you can use

git rev-list --count HEAD -- <filename>

Upvotes: 1

Related Questions