乐闻世界logo
搜索文章和话题

How can i view a git log of just one users commits?

2个答案

1
2

To view Git logs for a specific user's commits, you can use the git log command with the --author option to specify the author's name. This will filter the commits to show only those matching the specified author. The basic format is:

bash
git log --author="username"

Replace "username" with the real name or part of the email address of the user you want to view. Git will display all commits matching the username fragment.

For example, if you want to view all logs submitted by John Doe, you can run:

bash
git log --author="John Doe"

If you know the user's email address and want a more precise filter, you can write:

bash
git log --author=johndoe@example.com

Additionally, for more refined searches, you can use regular expressions:

bash
git log --author="^John"

This command will display all commits from authors whose names start with 'John'.

Example:

Suppose I participated in a project named example-project and made many contributions. The project manager wants to view all my commit records, and my Git username is Alex. The project manager can open a terminal or command prompt in the project's root directory and enter the following command:

bash
git log --author="Alex"

This will output all commits I authored, including commit hashes, commit messages, dates, and times, among other details. The project manager can analyze this information to assess my workload and contributions.

2024年6月29日 12:07 回复

This applies to the two most common ways of viewing history: using gitk and git log.

You don't need to use the full name:

shell
git log --author="Jon"

This will match commits made by "Jonathan Smith".

shell
git log --author=Jon

and

shell
git log --author=Smith

also work. If no spaces are needed, quotes are optional.

--all If you intend to search all branches in the repository rather than just the ancestors of the current commit, add it.

You can easily match multiple authors because regular expressions are the underlying mechanism for this filter.

Therefore, to list commits by Jonathan or Adam, you can do the following:

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

To exclude commits by specific authors or a group of authors using the regular expression mentioned in this question, you can combine negative lookahead with the --perl-regexp option:

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

Alternatively, you can exclude commits created by Adam using a pipe in bash:

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

If you want to exclude commits by Adam (but not necessarily created by him), replace %an with %cn.

2024年6月29日 12:07 回复

你的答案