How can I view a git log of just one user's commits?

GitVersion ControlGit Log

Git Problem Overview


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

Git Solutions


Solution 1 - Git

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/

Solution 2 - Git

git log --author="that user"

Solution 3 - Git

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

Solution 4 - Git

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 https://stackoverflow.com/questions/18750808/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.

Solution 5 - Git

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

Use this :-

git log --author="username" --pretty=format:"%h - %an, %ar : %s"

Solution 6 - Git

If you want to filter your own commits:

git log --author="<$(git config user.email)>"

Solution 7 - Git

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

Solution 8 - Git

cat | git log --author="authorName" > author_commits_details.txt

This gives your commits in text format.

Solution 9 - Git

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

Solution 10 - Git

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

Usage

```bash
$ 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

Solution 11 - Git

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

Solution 12 - Git

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

Solution 13 - Git

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.

Solution 14 - Git

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

git log --author="Developer1"

git log --author "Developer1"

Solution 15 - Git

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

Solution 16 - Git

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 :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmarkdorisonView Question on Stackoverflow
Solution 1 - GitAdam DymitrukView Answer on Stackoverflow
Solution 2 - GitwilhelmtellView Answer on Stackoverflow
Solution 3 - GitslottView Answer on Stackoverflow
Solution 4 - GitustunView Answer on Stackoverflow
Solution 5 - GitSireesh YarlagaddaView Answer on Stackoverflow
Solution 6 - GitLuca FaggianelliView Answer on Stackoverflow
Solution 7 - GitsjasView Answer on Stackoverflow
Solution 8 - GitJohnsa PhilipView Answer on Stackoverflow
Solution 9 - GitthreeView Answer on Stackoverflow
Solution 10 - GitInsaneBotView Answer on Stackoverflow
Solution 11 - GitFrank ForteView Answer on Stackoverflow
Solution 12 - GitdiEchoView Answer on Stackoverflow
Solution 13 - Gitsurajs1nView Answer on Stackoverflow
Solution 14 - GitharshainfoView Answer on Stackoverflow
Solution 15 - GitVinod KumarView Answer on Stackoverflow
Solution 16 - GitPatrick DeVivoView Answer on Stackoverflow