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.
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Compile and build with single command line Java (L
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
I found the following to be useful to see who had the most lines that were currently in the code base:
The other answers have mostly focused on lines changed in commits, but if commits don't survive and are overwritten, they may just have been churn. The above incantation also gets you all committers sorted by lines instead of just one at a time. You can add some options to git blame (-C -M) to get some better numbers that take file movement and line movement between files into account, but the command might run a lot longer if you do.
Also, if you're looking for lines changed in all commits for all committers, the follow little script is helpful:
http://git-wt-commit.rubyforge.org/#git-rank-contributors
This gives some statistics about the author, modify as required.
Using Gawk:
Using Awk on Mac OSX:
EDIT (2017)
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.Usage:
@mmrobins @AaronM @ErikZ @JamesMishra provided variants that all have an problem in common: they ask git to produce a mixture of info not intended for script consumption, including line contents from repository on the same line, then match the mess with a regexp.
This is a problem when some lines aren't valid UTF-8 text, and also when some lines happen to match the regexp (this happened here).
Here's a modified line that doesn't have these problems. It requests git to output data cleanly on separate lines, which makes it easy to filter what we want robustly:
You can grep for other strings, like author-mail, committer, etc.
Perhaps first do
export LC_ALL=C
(assumingbash
) to force byte-level processing (this also happens to speed up grep tremendously from the UTF-8-based locales).A solution was given with ruby in the middle, perl being a little more available by default here is an alternative using perl for current lines by author.
The question asked for information on a specific author, but many of the answers were solutions that returned ranked lists of authors based on their lines of code changed.
This was what I was looking for, but the existing solutions were not quite perfect. In the interest of people that may find this question via Google, I've made some improvements on them and made them into a shell script, which I display below. An annotated one (which I will continue to maintain) can be found on my Github.
There are no dependencies on either Perl or Ruby. Furthermore, whitespace, renames, and line movements are taken into account in the line change count. Just put this into a file and pass your Git repository as the first parameter.
In case anyone wants to see the stats for every user in their codebase, a couple of my coworkers recently came up with this horrific one-liner:
(Takes a few minutes to crunch through our repo, which has around 10-15k commits.)