git: find largest commit(s)
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.
you can use git log --format=format:"%H" --shortstat
.
It will output something like
b90c0895b90eb3a6d1528465f3b5d96a575dbda2
2 files changed, 32 insertions(+), 7 deletions(-)
642b5e1910e1c2134c278b97752dd73b601e8ddb
11 files changed, 835 insertions(+), 504 deletions(-)
// other commits skipped
Seems like an easily parsed text.
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.
精彩评论