347

Is it possible to list all users that contributed to a project (users that have done commits) in Git?

Any additional statistics?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ritam Nemira
  • 4,051
  • 4
  • 26
  • 21

9 Answers9

640

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
avs099
  • 10,937
  • 6
  • 60
  • 110
Pedro Nascimento
  • 13,136
  • 4
  • 36
  • 64
  • 3
    Note that if you want to use this command from within a script, or something like "ant", you must specify a revision or it outputs nothing. For the current revision you can use HEAD: `git shortlog -sn HEAD` – Majenko May 22 '14 at 18:03
  • 64
    To get e-mail addresses as well, add `-e`. – mic_e Oct 30 '14 at 12:47
  • 11
    To show users from all branches (not only the ones in the current branch) you have to add `--all` flag – Gian Marco Jul 06 '15 at 06:58
  • 4
    what if I dont want the number of commits? – Wearybands Jul 26 '18 at 11:45
  • 5
    This is also great for checking who touched a specific file rather than the whole project. `git shortlog --summary --numbered ` – jxramos Feb 04 '19 at 23:02
  • Is it possible to list the users that have access currently? – Nevin Oct 16 '19 at 01:34
  • 1
    @Nevin no because this does not have any correlation with github access. This is just parsing git history. You should be able to do so through their web API, but it's out of scope here. – Pedro Nascimento Oct 16 '19 at 15:00
60

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 email

Other placeholders are described in the pretty print documentation of git log.

Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68
Guillaume Vincent
  • 13,355
  • 13
  • 76
  • 103
  • I think the `%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... – ssc Jun 27 '18 at 12:21
  • 2
    @ssc committer email can be different from author email. %n is for new line to find those differences – Guillaume Vincent Jun 27 '18 at 13:52
  • 2
    Use `git log --pretty="%aN <%aE>%n%cN <%cE>" | sort | uniq ` to respect a `.mailmap` file – MaxNoe Jan 19 '22 at 14:48
  • adding the extra `uniq` parameter `-c` and sorting again you can get also the count per author displayed. ex: `| sort | uniq -c | sort` – darul75 Sep 29 '22 at 12:05
30

You can try this:

git log | grep Author: | sort -u
Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68
Santa Zhang
  • 884
  • 8
  • 13
12

(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 information

In 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-next in the current merge window, I don't care so much about who wrote a patch, as what git tree it 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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
5

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

  • 1
    you should probably add a note that after setting this you can simply call `git contributors` – lohfu May 25 '20 at 12:36
4

Another option can be:

git log --format='%aN' | sort -u
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
3

Another 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.

Patrick DeVivo
  • 755
  • 1
  • 9
  • 13
  • Looks awesome. Cool and easy way to interact with git. Kind of interesting that [mergestat lite](https://github.com/mergestat/mergestat-lite) is 10x more stars than mergestat haha. – Huan Ran Ng Jul 06 '23 at 03:08
2

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

Fazli Zekiqi
  • 531
  • 2
  • 7
  • 14
1

I haven't got around to testing it myself yet, but this looks really nice for project statistics for a Git repository: https://github.com/visionmedia/git-extras

Check out the bin catalog to see the the different scripts.

For example, the git-count script (commit count per committer):

git shortlog -n $@ | grep "):" | sed 's|:||'
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Daniel Lee
  • 7,709
  • 2
  • 48
  • 57
  • 1
    git shortlog -ns seems less hackish – TomDLT Oct 20 '16 at 08:47
  • @TomDLT since I posted this 4 years ago, this example script in git-extras has changed. But I think my advice to look at git scripts from projects like git-extras or from peoples' dotfiles is still great advice. If you are looking for interesting git commands then I would recommend Gary Bernhardt's dotfiles as well: https://github.com/garybernhardt/dotfiles/tree/master/bin – Daniel Lee Oct 20 '16 at 08:54