Reputation: 457
I need to extract some data from git projects and for this purpose, I am working on a script to output the results in the format that I need.
One of the things I want to see is how many commits have updated files of a particular extension. For example, I want to count all the commits that have updated .tex
files in a project (I don't care if other files were changed as well).
What I am getting from my script seems to make sense, but I would like to know if there is a built-in, similar functionality in git, or a quick workaround to be able to gather this data, in order to validate my output.
Upvotes: 1
Views: 167
Reputation: 45819
You can list commits that affected any file matching an extension
git log :/*.txt :/**/*.txt
(Note that the fist pattern says to look in the worktree root directory, and the second says to look in any directory under the root. In my tests just using :/*.txt
seems to work, but based on the docs I can't see why. If anyone can fill in that blank, please do...)
You can simplify the output and then feed it to wc
git log --format=%H :/*.txt :/**/*.txt |wc -l
You might need to broaden the search, as the above will only show what's reachable from HEAD
.
git log --all --format=%H :/*.txt :/**/*.txt |wc -l
You also might have to avoid history simplification.
git log --all --full-history --format=%H :/*.txt :/**/*.txt |wc -l
There are many other options you can use to control exactly what's included in the output (e.g. --diff-filter
if you're only interested in certain types of file modification, etc.)
Upvotes: 3