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

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

This question is related to git version-control git-log

The answer is


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

This gives your commits in text format.


If you want to filter your own commits:

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

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.


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

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


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

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.


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


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


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 | awk '{print $1}' | xargs git show

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

Use this :-

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

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

git log --author="that user"

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

git log --author="Developer1"

git log --author "Developer1"

Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to version-control

How can I switch to another branch in git? Do I commit the package-lock.json file created by npm 5? Project vs Repository in GitHub Remove a modified file from pull request Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository." Git: How to squash all commits on branch git: updates were rejected because the remote contains work that you do not have locally Sourcetree - undo unpushed commits Cannot checkout, file is unmerged Git diff between current branch and master but not including unmerged master commits

Examples related to git-log

How to get commit history for just one branch? How do I see the commit differences between branches in git? Commit history on remote repository How to exit git log or git diff How to search a Git repository by commit message? Get a list of all git commits, including the 'lost' ones How do I run git log to see changes only for a specific branch? How can I view a git log of just one user's commits? Viewing unpushed Git commits How to view file history in Git?