Is there a command I can invoke which will count the lines changed by a specific author in a Git repository? I know that there must be ways to count the number of commits as Github does this for their Impact graph.
When you install Git, you also get its visual tools, gitk and git-gui . gitk is a graphical history viewer. Think of it like a powerful GUI shell over git log and git grep . This is the tool to use when you're trying to find something that happened in the past, or visualize your project's history.
The git log command returns all of the commits that have been made to the repository. This command lists the latest commits in chronological order, with the latest commit first. The following screenshot shows how to use the command to view all commits in the current repository.
This gives some statistics about the author, modify as required.
Gawk
:git log --author="_Your_Name_Here_" --pretty=tformat: --numstat \ | gawk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s\n", add, subs, loc }' -
Awk
on Mac OSX:git log --author="_Your_Name_Here_" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -
count-lines
git-alias:Simply create count-lines
alias (once per system), like:
git config --global alias.count-lines "! git log --author=\"\$1\" --pretty=tformat: --numstat | awk '{ add += \$1; subs += \$2; loc += \$1 - \$2 } END { printf \"added lines: %s, removed lines: %s, total lines: %s\n\", add, subs, loc }' #"
And use each time later, like:
git count-lines [email protected]
For Windows, works after adding Git-Bash to
PATH
(environment-variable).
For Linux, maybe replaceawk
part withgawk
.
For MacOS, works without any change.
There is a new package on github that looks slick and uses bash as dependencies (tested on linux). It's more suitable for direct usage rather than scripts.
It's git-quick-stats (github link).
Copy git-quick-stats
to a folder and add the folder to path.
mkdir ~/source cd ~/source git clone [email protected]:arzzen/git-quick-stats.git mkdir ~/bin ln -s ~/source/git-quick-stats/git-quick-stats ~/bin/git-quick-stats chmod +x ~/bin/git-quick-stats export PATH=${PATH}:~/bin
Usage:
git-quick-stats
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With