如何查看一个用户提交的 git 日志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4259996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:32:10  来源:igfitidea点击:

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

gitversion-controlgit-log

提问by markdorison

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

使用时git log,如何按用户进行过滤,以便仅查看该用户的提交?

回答by Adam Dymitruk

This works for both git logand gitk- the 2 most common ways of viewing history.
You don't need to use the whole name:

这适用于git loggitk- 两种最常见的查看历史的方式。
您不需要使用全名:

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 --allif you intend to search all branches and not just the current commit's ancestors in your repo.

添加--all如果你打算搜索所有分支,而不仅仅是当前提交的祖先在你的回购协议。

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:

您还可以轻松匹配多个作者,因为正则表达式是此过滤器的基础机制。因此,要列出 Jonathan 或 Adam 的提交,您可以这样做:

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 lookaheadin combination with the --perl-regexpswitch:

为了排除使用正则表达式的特定作者或一组作者的提交,如本问题所述,您可以将否定前瞻--perl-regexp开关结合使用:

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

Alternatively, you can exclude commits authored by Adam by using bashand piping:

或者,您可以通过使用bash和管道排除由 Adam 创作的提交:

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 %anwith %cn. More details about this are in my blog post here: http://dymitruk.com/blog/2012/07/18/filtering-by-author-name/

如果您想排除由 Adam 提交(但不一定是作者)的提交,请替换%an%cn. 有关这方面的更多详细信息,请参阅我的博客文章:http: //dymitruk.com/blog/2012/07/18/filtering-by-author-name/

回答by wilhelmtell

git log --author="that user"

回答by slott

On github there is also a secretway...

在github上也有一个秘密的方式......

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=jingwenoshows a list of commits to the Dynjs project

您可以通过附加 param 在提交视图中按作者过滤提交?author=github_handle。例如,链接https://github.com/dynjs/dynjs/commits/master?author=jingweno显示了 Dynjs 项目的提交列表

回答by ustun

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 的联机帮助页。按 / 搜索“作者”,然后输入“作者”,然后按 Enter。多次输入“n”以进入相关部分,其中显示:

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)

注意,这会给你提交的作者,但在 Git 中,作者可以是不同于提交者的人(例如在 Linux 内核中,如果你以普通用户的身份提交补丁,它可能由另一个管理用户提交.) 请参阅Git 中作者和提交者之间的区别?更多细节)

Most of the time, what one refers to as the user is both the committer and the author though.

在大多数情况下,人们所指的用户既是提交者又是作者。

回答by Sireesh Yarlagadda

To pull more details - (Here %anrefers to author)

拉取更多细节 - (此处%an指作者)

Use this :-

用这个 :-

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

回答by Johnsa Philip

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

This gives your commits in text format.

这以文本格式提供您的提交。

回答by Luca Faggianelli

If you want to filter your own commits:

如果要过滤自己的提交:

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

回答by three

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

回答by InsaneBot

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

试试这个工具 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

回答by sjas

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 }' | xargs git show