Course Tonight

Course Tonight

Did You Know?

We design Docy for the readers, optimizing not for page views or engagement

Chapter 48: Git Statistics

Estimated reading: 3 minutes 6 views
Parameter Details
-n, --numbered Sort output according to the number of commits per author instead of alphabetic order.
-s, --summary Only provide a commit count summary.
-e, --email Show the email address of each author.
--format[=<format>] Instead of the commit subject, use some other information to describe each commit. <format> can be any string accepted by the --format option of git log.
-w[<width>[,<indent1>[,<indent2>]]] Linewrap the output by wrapping each line at width. The first line of each entry is indented by indent1 number of spaces, and subsequent lines are indented by indent2 spaces.
<revision range> Show only commits in the specified revision range. Default to the whole history until the current commit.
[--] <path> Show only commits that explain how the files matching path came to be. Paths may need to be prefixed with “– ” to separate them from options or the revision range.

Section 48.1: Lines of Code per Developer

git ls-tree -

r HEAD | sed -Ee 's/^.{53}//' | \ while read filename; do file "$filename"; done | \ grep -E ': .*text' | sed -E -e 's/: .*//' | \ while read filename; do git blame --line-porcelain "$filename"; done | \ sed -n 's/^author //p' | \ sort | uniq -c | sort -rn

Section 48.2: Listing Each Branch and Its Last Revision’s Date

for k in `git

branch -a | sed s/^..//`; do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k --`\\t"$k";done | sort

Section 48.3: Commits per Developer

Git shortlog is used to summarize the git log outputs and group the commits by author.

By default, all commit messages are shown, but the argument --summary or -s skips the messages and gives a list of authors with their total number of commits.

To display names and the number of commits:

git shortlog -sn

To display names along with their email IDs and the number of commits:

git shortlog -sne

Alternatively, you can use the following command:

git log --pretty=format:%ae | gawk -- '{ ++c[$0]; } END { for(cc in c) printf "%5d %s\n",c[cc],cc; }'

Note: Commits by the same person may not be grouped together if their name and/or email address has been spelled differently. To resolve this, refer to the .mailmap feature.

Section 48.4: Commits per Date

To count the number of commits per date:

git log --pretty=format:"%ai" | awk '{print " : "$1}' | sort -r | uniq -c

Section 48.5: Total Number of Commits in a Branch

To show the total number of commits in a branch:

git log --pretty=oneline | wc -l

Section 48.6: List All Commits in Pretty Format

To list all commits in a pretty format, including date, user, and commit message:

git log --pretty=format:"%Cgreen%ci %Cblue%cn %Cgreen%cr%Creset %s"

Section 48.7: Find All Local Git Repositories on Computer

To list all the git repository locations on your computer, you can run the following commands:

Using find:

find $HOME -type d -name ".git"

Using locate (assuming you have it):

locate .git | grep git$

Using locate with GNU locate or mlocate:

locate -ber \\.git$

Section 48.8: Show the Total Number of Commits per Author

To get the total number of commits that each developer or contributor has made on a repository, you can use the git shortlog command:

git shortlog -s

To calculate the results on all branches, add the --all flag to the command:

git shortlog -s --all

Leave a Comment

Share this Doc

Chapter 48: Git Statistics

Or copy link

CONTENTS