Ian Michael Williams Ian Michael Williams - 1 year ago 78
Git Question

How can I determine what % of git commits touch a file or directory?

I'm trying to use git log to look through the commit history and figure out, given a period of time, how many commits touched certain sub-folders of the codebase.

Maybe there is a tool out there that reports this sort of statistics. But I feel like this should be possible as a one-liner or short script of commands.

I'm on Windows, but a unix friendly script would be great.

Answer Source

The easy way to get the number of commits that touched a files is to just look at the log for that file.

git log --follow -- path/to/my/file

The --follow will follow renames, and the -- is there in case the file path is ambiguous (and looks like a branch name or something).

You can count the results with:

git log --format=oneline --follow -- _exec.sh  | wc -l

The total number of commits is given by:

git rev-list HEAD | wc -l

These commands will look at the current branch (and its ancestors) only, you can look at stats for all branches by passing --all to both rev-list and log.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download