1602

When using git log, how can I filter by user so that I see only commits from that user?

David Thibault
  • 8,638
  • 3
  • 37
  • 51
markdorison
  • 139,374
  • 27
  • 55
  • 71

16 Answers16

2217

This works for both git log and gitk - the 2 most common ways of viewing history.
You don't need to use the whole name:

git log --author="Jon"

will match a commit made by "Jonathan Smith"

git log --author=Jon

and

git log --author=Smith

would also work. The quotes are optional if you don't need any spaces.

Add --all if you intend to search all branches and not just the current commit's ancestors in your repo.

You can also easily match on multiple authors as regex is the underlying mechanism for this filter. So to list commits by Jonathan or Adam, you can do this:

git log --author="\(Adam\)\|\(Jon\)"

In order to exclude commits by a particular author or set of authors using regular expressions as noted in this question, you can use a negative lookahead in combination with the --perl-regexp switch:

git log --author='^(?!Adam|Jon).*$' --perl-regexp

Alternatively, you can exclude commits authored by Adam by using bash and piping:

git log --format='%H %an' | 
  grep -v Adam | 
  cut -d ' ' -f1 | 
  xargs -n1 git log -1

If you want to exclude commits commited (but not necessarily authored) by Adam, replace %an with %cn. More details about this are in my blog post here: http://dymitruk.com/blog/2012/07/18/filtering-by-author-name/

Dimitrios Mistriotis
  • 2,626
  • 3
  • 28
  • 45
Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • 13
    Is there a way to do the opposite? Say - I want to see all commits except for Jon's. – Ian Robinson Apr 28 '11 at 18:58
  • 4
    @Ian as for git help log "Jon" is a regular expression so it should be pretty easy – sumek May 11 '11 at 16:12
  • 2
    git log --format=%an | egrep -v 'Jon*' | xargs -n 1 git log -1 – Adam Dymitruk May 24 '11 at 04:45
  • oops.. forget that. but you get the gist. get a "not in" functionality out of piping through egrep -v and other tricks on the command line. – Adam Dymitruk May 24 '11 at 05:08
  • On my instance of git, I needed to add the `-E` flag to get the 'multiple user' example above to work. Wanted to make sure my experience isn't unique before I edit the answer – JRaymond Aug 26 '13 at 18:27
  • Is this command for the commits on the current branch only or is this for the entire project? How would be for the entire project? – Ritam Nemira Oct 08 '14 at 12:53
  • you would add `--all` to have log list commits from all branches instead of just current commit's ancestors. Git implicitly runs `git log HEAD` when you issue `git log`. – Adam Dymitruk Oct 14 '14 at 23:37
  • 5
    Any way to make `gitk` leave out the parent commits from other authors? (They are shown with white circles.) In contrast, `git log --graph` doesn't show the parent commits; it only shows the given author's commits. I would love to see the same output in `gitk`. *(Already checked Preferences and Edit View - couldn't find anything useful.)* – ADTC May 06 '16 at 10:27
  • @IanRobinson Another way to exclude certain committers -- PERL regular expressions support "negative look-ahead assertions". So, you can construct an expression that requires that the starting point not match an expression that matches another regexp anywhere later in the string. Example, to exclude all author strings that contain 'Jon': `git log --author='^(?!.*Jon)' --perl-regexp` – Jonathan Gilbert Jun 21 '16 at 20:54
  • Oh, just noticed that a variation on that is further down in the original answer. Silly me :-) – Jonathan Gilbert Jun 21 '16 at 20:55
  • 3
    Beware this is case sensitive – chtenb Nov 10 '16 at 11:55
  • 1
    Add --no-merges if you want to exclude merge commits from that list. – thegreendroid Jun 02 '17 at 02:02
  • 1
    I note that the following syntax seems to work also: git log --author jeff (that is, no equal sign). – Jeff Nov 28 '17 at 17:53
  • 1
    Watch out for the quotation mark wrapping the pattern regex. Mine did not work since I used single quote(') instead of double quote ("). `git log --author='^(?!.*Charith)' --perl-regexp` did not work. `git log --author="^(?!.*Charith)" --perl-regexp` did work – charith.arumapperuma Mar 01 '18 at 17:13
  • @ADTC: I asked separate question: https://stackoverflow.com/questions/49219779/how-to-avoid-showing-parent-commits-in-gitk-when-filtering-by-author – Eugene Maksimov Mar 11 '18 at 12:04
85
git log --author="that user"
wilhelmtell
  • 57,473
  • 20
  • 96
  • 131
54

On github there is also a secret way...

You can filter commits by author in the commit view by appending param ?author=github_handle. For example, the link https://github.com/dynjs/dynjs/commits/master?author=jingweno shows a list of commits to the Dynjs project

phuclv
  • 37,963
  • 15
  • 156
  • 475
slott
  • 3,266
  • 1
  • 35
  • 30
35
git help log

gives you the manpage of git log. Search for "author" there by pressing / and then typing "author", followed by Enter. Type "n" a few times to get to the relevant section, which reveals:

git log --author="username"

as already suggested.

Note that this will give you the author of the commits, but in Git, the author can be someone different from the committer (for example in Linux kernel, if you submit a patch as an ordinary user, it might be committed by another administrative user.) See Difference between author and committer in Git? for more details)

Most of the time, what one refers to as the user is both the committer and the author though.

Community
  • 1
  • 1
ustun
  • 6,941
  • 5
  • 44
  • 57
  • 26
    @James I think your negativity here is unwarranted. I was simply trying to teach him how to look it up from the command line in case he forgets. I think you are mistaking me for a person who just says RTFM, but I included the answer in my response. – ustun Sep 06 '13 at 06:25
  • 12
    It's not negativity. It's the fact that people come here asking for advice, and a lot of folks want to respond with some variant of RTFM. Bodes poorly for the community. – James Sep 06 '13 at 15:26
  • 13
    @James I have to agree with ustun here. He *did* answer the question, *and* he offered a strategy for finding the answer which is helpful for finding answers to other git-related questions. – Peter Dec 31 '14 at 17:21
  • 1
    The reason there is a divergence of opinion here is because the statement, "Search for 'author' there" can be functionally replaced with "Use magic" as there is not a sensible reason to predict the keyword author over synonyms or abbreviations. Thus the perception of the RTFM response. – Harrichael Mar 21 '16 at 15:40
  • 5
    I don't think it's quite as black and white as this. Now, I agree with unstun that we ought to educate people how to do things for themselves - that's a good idea. Where unstun went slightly wrong is making the assumptions a) That the OP knows how to search a man page, and more importantly b) That the OP knows to search for 'author'. They may have searched for 'committer' or 'name' or something. – John Hunt Mar 20 '17 at 11:37
  • 6
    @JohnHunt you are right, it had never occurred to me to explain what search means and how it is done at the time. Kind of assumed it. Fixing the text slightly. – ustun Mar 20 '17 at 16:06
32

To pull more details - (Here %an refers to author)

Use this :-

git log --author="username" --pretty=format:"%h - %an, %ar : %s"
phuclv
  • 37,963
  • 15
  • 156
  • 475
Sireesh Yarlagadda
  • 12,978
  • 3
  • 74
  • 76
  • 3
    And if you want their Email address use format `%ae` instead of `%an` (which gave Name.) – MarkHu Apr 27 '16 at 16:57
  • `--author` actually searches by the author name and not committer name. I would change `"username"` to author – Algorithmatic Jun 29 '16 at 06:43
  • Syntax of [commit fields available in `--pretty=format`](https://git-scm.com/docs/pretty-formats#Documentation/pretty-formats.txt-emHem) – dlauzon Mar 01 '22 at 17:10
26

If you want to filter your own commits:

git log --author="<$(git config user.email)>"
Luca Faggianelli
  • 2,032
  • 20
  • 23
20

Since the other question was (possibly wrongfully so?) locked, I will just put this here:

show authors with their commit counts:

git shortlog -nse

find all commits for specific USERNAME:

git log --author=USERNAME --oneline --color=never | awk '{print $1}' | xargs git show
sjas
  • 18,644
  • 14
  • 87
  • 92
  • 1
    Thanks, this was helpful. In case anybody else also wasn't getting any output for the `xargs git show` part, perhaps like me you need to add `--color=never` to the `git log` part (I forget that the color settings in my config sometimes mess other things up). – Max Starkenburg Sep 19 '21 at 20:56
16
cat | git log --author="authorName" > author_commits_details.txt

This gives your commits in text format.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Johnsa Philip
  • 1,725
  • 4
  • 14
  • 12
15

try this tool https://github.com/kamranahmedse/git-standup

Usage

$ git standup [-a <author name>] 
              [-w <weekstart-weekend>] 
              [-m <max-dir-depth>]
              [-f]
              [-L]
              [-d <days-ago>]
              [-D <date-format>] 
              [-g] 
              [-h]

Below is the description for each of the flags

- `-a`      - Specify author to restrict search to (name or email)
- `-w`      - Specify weekday range to limit search to (e.g. `git standup -w SUN-THU`)
- `-m`      - Specify the depth of recursive directory search
- `-L`      - Toggle inclusion of symbolic links in recursive directory search
- `-d`      - Specify the number of days back to include
- `-D`      - Specify the date format for "git log" (default: relative)
- `-h`      - Display the help screen
- `-g`      - Show if commit is GPG signed or not
- `-f`      - Fetch the latest commits beforehand
Mike Slinn
  • 7,705
  • 5
  • 51
  • 85
InsaneBot
  • 2,422
  • 2
  • 19
  • 31
11

You can even abbreviate this a bit by simply using part of the user name:

git log --author=mr  #if you're looking for mrfoobar's commits
three
  • 8,262
  • 3
  • 35
  • 39
4

Show n number of logs for x user in colour by adding this little snippet in your .bashrc file.

gitlog() {
    if [ "$1" ] && [ "$2" ]; then
       git log --pretty=format:"%h%x09 %C(cyan)%an%x09 %Creset%ad%x09 %Cgreen%s" --date-order -n "$1" --author="$2"
    elif [ "$1" ]; then
       git log --pretty=format:"%h%x09 %C(cyan)%an%x09 %Creset%ad%x09 %Cgreen%s" --date-order -n "$1"
    else
        git log --pretty=format:"%h%x09 %C(cyan)%an%x09 %Creset%ad%x09 %Cgreen%s" --date-order
    fi
}

alias l=gitlog

To show the last 10 commits by Frank:

l 10 frank

To show the last 20 commits by anyone:

l 20

Frank Forte
  • 2,031
  • 20
  • 19
4

Although, there are many useful answers. Whereas, just to add another way to it. You can also use

git shortlog --author="<author name>" --format="%h %s"

It will show the output in the grouped manner:

<Author Name> (5):
  4da3975f dependencies upgraded
  49172445 runtime dependencies resolved
  bff3e127 user-service, kratos, and guava dependencies upgraded
  414b6f1e dropwizard :- service, rmq and db-sharding depedencies upgraded
  a96af8d3 older dependecies removed

Here, total of 5 commits are done by <Author Name> under the current branch. Whereas, you can also use --all to enforce the search everywhere (all the branches) in the git repository.

One catch: git internally tries to match an input <author name> with the name and email of the author in the git database. It is case-sensitive.

surajs1n
  • 1,493
  • 6
  • 23
  • 34
3

If using GitHub:

  • go to branch
  • click on commits

it will show list in below format

branch_x: < comment> 
author_name committed 2 days ago
  • to see individual author's commit ; click on author_name and there you can see all the commit's of that author on that branch
Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
xkeshav
  • 53,360
  • 44
  • 177
  • 245
2

You can use either = or "space". For instance following two commands return the same

git log --author="Developer1"

git log --author "Developer1"
harshainfo
  • 504
  • 7
  • 11
0

My case: I'm using source tree, I followed the following steps:

  1. Pressed CRL+3
  2. Changed dropdown authors
  3. Typed the name "Vinod Kumar"

enter image description here

Vinod Kumar
  • 1,191
  • 14
  • 12
0

A possible alternative is using a tool called mergestat which lets you run SQL queries against the commit history in a repo (among other things).

mergestat "SELECT * FROM commits WHERE author_name LIKE '%Jon%'"

It's a bit more verbose but can offer flexibility in finding specifically what you're looking for in a generic way.

For instance, filtering out merge commits and only showing commits in the past year, from a specific author:

mergestat "SELECT * FROM commits WHERE author_name LIKE '%Jon%' WHERE author_when > DATE('now', '-1 year') AND parents < 2"

Full disclosure: I'm a maintainer of the project :)

Patrick DeVivo
  • 755
  • 1
  • 9
  • 13