Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 799
markdorison Avatar asked Nov 23 '10 19:11

markdorison


People also ask

How do I search for commits done by a particular author?

So for looking for commits by “Adam Dymitruk” it's easier to just type git log --author="Adam" or use the last name if there more contributors with the same first name.

How can I see only my commits?

You should use the --author flag to the git-log command. You could then just type: git mylog and see your commits only.

How do I see my git log history?

`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.


1 Answers

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/

like image 139
16 revs, 5 users 82% Avatar answered Oct 18 '22 11:10

16 revs, 5 users 82%