Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

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

1 Answer

0 votes
by (27.5k points)

The two most common ways of viewing history are git log and gitk - t

You don't even have to write your whole name. For instance, putting only "Will" will match a commit made by "Will Smith"

$ git log --author="Will"

Likewise, "Smith" would also work

$ git log --author="Smith"

In case you intend to search all branches and not just the current commit's ancestors in your repository, you need to do --all 

Interesting fact 1: Git allows you to match on multiple authors as regular expression is the underlying mechanism for this filter. 

In order to list commits by Will or Jordan, you can do this:

$ git log --author="\(Jordan\)\|\(Will\)"

Interesting fact 2: Git allows you to exclude commits by a particular author or set of authors using regular expressions as noted in this question, you can use a negative look-ahead in combination with the --perl-regexp switch:

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

You can also exclude commits authored by Will by using bash and piping:

git log --format='%H %an' | 

  grep -v Will | 

  cut -d ' ' -f1 | 

  xargs -n1 git log -1

Note: If you want to exclude commits commited (but not necessarily authored by Will), replace %an with  %cn. 

Related questions

Browse Categories

...