使用gitlog时,如何按用户进行筛选,以便只看到该用户的提交?


当前回答

git help log

为您提供gitlog的手册页。按/,然后键入“author”,然后按Enter键,在那里搜索“作者”。键入“n”几次以进入相关部分,其中显示:

git log --author="username"

正如已经建议的那样。

注意,这将为您提供提交的作者,但在Git中,作者可以是与提交者不同的人(例如,在Linux内核中,如果您以普通用户身份提交补丁,则可能由其他管理用户提交)?有关详细信息)

大多数时候,人们所说的用户既是提交者,也是作者。

其他回答

这对gitlog和gitk都有效——这是查看历史的两种最常见的方式。您不需要使用整个名称:

git log --author="Jon"

将符合“乔纳森·史密斯”的承诺

git log --author=Jon

and

git log --author=Smith

也会起作用。如果不需要空格,引号是可选的。

如果您打算搜索所有分支,而不仅仅是当前提交的祖先,那么添加--all。

您还可以轻松匹配多个作者,因为正则表达式是此筛选器的基本机制。因此,要列出Jonathan或Adam的提交,可以执行以下操作:

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

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

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

或者,可以使用bash和piping排除Adam编写的提交:

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

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

试试这个工具https://github.com/kamranahmedse/git-standup

用法

$ git standup [-a <author name>] 
              [-w <weekstart-weekend>] 
              [-m <max-dir-depth>]
              [-f]
              [-L]
              [-d <days-ago>]
              [-D <date-format>] 
              [-g] 
              [-h]

以下是每个标志的说明

- `-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 shortlog --author="<author name>" --format="%h %s"

它将以分组方式显示输出:

<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

这里,<AuthorName>在当前分支下总共完成了5次提交。然而,您也可以使用--all在git存储库中的任何地方(所有分支)强制搜索。

一个陷阱:git内部试图将输入<author-name>与git数据库中作者的姓名和电子邮件匹配。它区分大小写。

git log --author="that user"

一种可能的替代方法是使用名为mergestat的工具,该工具允许您针对repo中的提交历史运行SQL查询(除其他外)。

mergestat "SELECT * FROM commits WHERE author_name LIKE '%Jon%'"

它有点冗长,但可以提供灵活性,以通用的方式具体查找您要查找的内容。

例如,过滤掉合并提交,仅显示过去一年中特定作者的提交:

mergestat "SELECT * FROM commits WHERE author_name LIKE '%Jon%' WHERE author_when > DATE('now', '-1 year') AND parents < 2"

完整披露:我是项目的维护者:)