Is it possible to list all users that contributed to a project (users that have done commits) in Git?
Any additional statistics?
To show all users & emails, and the number of commits in the CURRENT branch:
git shortlog --summary --numbered --email
Or simply:
git shortlog -sne
To show users from all branches (not only the ones in the current branch) you have to add --all flag:
git shortlog -sne --all
git shortlog -sn HEAD-e.--all flaggit shortlog --summary --numbered <pathToFile>If you want to be more specific in the list (find a list of unique committer and author), you could use git log:
git log --pretty="%an %ae%n%cn %ce" | sort -u
%an author name%ae author email%n new line%cn committer name%ce committer emailOther placeholders are described in the pretty print documentation of git log.
%n does not make too much sense in combination with (line-based) sort, does it ? The line logs author / committer name / email in separate lines, but sorts over the entire output...git log --pretty="%aN <%aE>%n%cN <%cE>" | sort | uniq to respect a .mailmap fileuniq parameter -c and sorting again you can get also the count per author displayed. ex: | sort | uniq -c | sort(users that have done commits)
Note: by default git shortlog groups commits by authors.
If you need to group them by committers, you will need Git 2.12 (Q1 2017)
git shortlog -snc
See commit 03f4082 (16 Dec 2016) by Jeff King (peff).
See commit fbfda15 (11 Oct 2016) by Linus Torvalds (torvalds).
(Merged by Junio C Hamano -- gitster -- in commit ad1b4e2, 27 Dec 2016)
Linus Torvalds himself introduces this feature:
shortlog: group by committer informationIn some situations you may want to group the commits not by author, but by committer instead.
For example, when I just wanted to look up what I'm still missing from
linux-nextin the current merge window, I don't care so much about who wrote a patch, as whatgit treeit came from, which generally boils down to "who committed it".So make git shortlog take a "
-c" or "--committer" option to switch grouping to that.
Great answers by @pedro-nascimento, by @mic_e and others already solve the problem.
In addition, you can add the following line to your .gitconfig
contributors = shortlog -e --summary --numbered
or in shell type
git config --global alias.contributors 'shortlog -e --summary --numbered'
And after that you can simply invoke: git contributors
git contributorsAnother option is using the mergestat CLI, which is a tool that allows you to run SQL queries on git history. So a query like:
SELECT
author_name,
author_email count(*),
count(*)
FROM commits
GROUP BY author_name, author_email
ORDER BY count(*) DESC
Will output a list of all commit authors in a repo, ordered by number of commits. Since it's just SQL, you can add filtering for commit timestamps, or sort by LOC added/removed, etc.
Full disclosure, I'm the maintainer/creator of the project, but wanted to share because I believe it could be useful for this type of use case.
There's also the summary command which prints out git stats by author in a repo.
I am using GHI to open issues and where I can assign issues to specific users as long as I know their usernames
I don't if this is going to be helpful for someone but I am just going to leave the solution that worked for me here:
To get only the authors username from the GitHub I ran
git shortlog -sne | grep + | sed -e "s/.*+//; s/@.*//"
which will only list the username of the authors on the current project.
Then i can pick an username and assign an issue to him/her.
FOR ANYONE WHO WANTS TO OPEN ISSUES AND/OR ASSIGN TO SOMEONE FROM CMD/TERMINAL, HERE THE DOCUMENTATION OF THE GHI https://github.com/stephencelis/ghi
If you have git-extras installed you can use one of its helpful (and easy to remember) commands, such as git authors or git count.
A list of authors, including email addresses, ordered by commit count:
git authors --list
A list of authors and the number of their contributions i.e. commits:
git count --all
The commands are shell scripts that use Git commands themselves. You can inspect the source code on GitHub, e.g.
git-authors is implemented as:
git shortlog HEAD -sne | awk '{$1=""; sub(" ", ""); print}' | awk -F'<' '!x[$1]++' | awk -F'<' '!x[$2]++'
git-count is implemented as:
git shortlog -n -s | awk '{print substr($0,index($0,$2)) " (" $1 ")"}'
In my case, I want a) list all contributors mentioned in Co-authored-by: and b) add a link to the avatar of all contributors coming from squash merged pull requests.
For that, I wrote GitHub Contributors List.
jbang https://github.com/koppor/github-contributors-list/blob/HEAD/gcl.java --owner=<owner> --repo=<repository> --startrevision=<startCommitRevStr> --endrevision=<endCommitRevStr> <repositoryPath>
The resulting rendered Markdown table looks as follows:
See https://github.com/JabRef/blog.jabref.org/blob/main/_posts/2024-04-03-JabRef5-13.md for the full example.