git: find largest commit(s)

Viewed 3784

What would be a way to find largest commits (i.e. commits introducing most changes, for instance counted as the number of added/removed lines) in a git repo?

Note that I really want largest commits, not largest files, so git find fat commit is not helpful here.

2 Answers

For anyone wanting to get a simple list of largest to smallest commits (by the amount of changes made in a commit) I took @max's answer and parsed and ordered the result.

git log --format=format:"%H" --shortstat | perl -00 -ne 'my ($hash, $filesChanged, $insertions, $deletions) = $_ =~ /(?:[0-9a-f]+\n)*([0-9a-f]+)\n(?: (\d+) files? changed,)?(?: (\d+) insertions?...,?)?(?: (\d+) deletions?...)?/sg; print $hash, "\t", $insertions + $deletions, "\n"' | sort -k 2 -nr

That takes all the commits, adds together the number of insertions and deletions for each, and then orders that list from highest to lowest. To get just the top ten largest commits add | head -10 to the end.

Related