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

mar*_*son 1178 git version-control git-log

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

Ada*_*ruk 1603

这适用于两者git loggitk- 两种最常见的查看历史记录的方式.您不需要使用整个名称.

git log --author="Jon"
Run Code Online (Sandbox Code Playgroud)

将匹配"乔纳森史密斯"的提交

git log --author=Jon
Run Code Online (Sandbox Code Playgroud)

git log --author=Smith
Run Code Online (Sandbox Code Playgroud)

也会有用.如果您不需要任何空格,则引号是可选的.

添加--all如果你打算搜索所有分支,而不是只是在你的回购最近提交的祖先.

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

git log --author="\(Adam\)\|\(Jon\)"
Run Code Online (Sandbox Code Playgroud)

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

git log --author='^(?!Adam|Jon).*$' --perl-regexp
Run Code Online (Sandbox Code Playgroud)

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

git log --format='%H %an' | 
  grep -v Adam | 
  cut -d ' ' -f1 | 
  xargs -n1 git log -1
Run Code Online (Sandbox Code Playgroud)

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

  • 有没有办法做相反的事情?说 - 我想看看除Jon之外的所有提交. (8认同)
  • @Ian和git帮助日志"Jon"是一个正则表达式所以它应该很容易 (4认同)
  • 任何使`gitk`的方法都忽略了其他作者的父承诺?(它们以白色圆圈显示.)相反,`git log --graph`不显示父提交; 它只显示给定作者的提交.我希望在`gitk`中看到相同的输出.*(已经检查过偏好设置和编辑视图 - 找不到任何有用的东西.)* (4认同)
  • git log --format =%an | egrep -v'Jon*'| xargs -n 1 git log -1 (2认同)
  • 当心这是区分大小写的 (2认同)

slo*_*ott 42

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

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

  • 有什么办法可以跨分支查看吗?像 commits/all 之类的东西? (2认同)
  • 你是怎么找到这个的?支持哪些其他标志? (2认同)

ust*_*tun 31

git help log
Run Code Online (Sandbox Code Playgroud)

为您提供git log的联机帮助页.按/然后键入"author",然后按Enter键搜索"author".输入"n"几次以进入相关部分,其中显示:

git log --author="username"
Run Code Online (Sandbox Code Playgroud)

如已经建议的那样

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

大多数时候,人们指的是用户既是提交者又是作者.

  • @James我认为你的消极情绪是没有根据的.我只是试图教他如何从命令行查找它,以防他忘记.我认为你错误地告诉我一个刚刚说RTFM的人,但我在回答中包含了答案. (21认同)
  • 这不是消极性.事实上,人们来到这里寻求建议,很多人都希望用RTFM的某些变体做出回应.这对社区来说很糟糕. (11认同)
  • @James我必须同意ustun在这里.他*做了*回答问题,*和*他提供了一个寻找答案的策略,这有助于找到其他与git相关的问题的答案. (11认同)
  • @JohnHunt你是对的,我从未想过要解释搜索的含义以及当时的工作方式.有点假设它.略微修复文本. (5认同)
  • 我不认为它像这样黑白.现在,我同意我们应该教育人们如何为自己做事 - 这是一个好主意.在unstun略有错误的地方做出假设a)OP知道如何搜索手册页,更重要的是b)OP知道搜索"作者".他们可能搜索过"提交者"或"姓名"等. (3认同)

Sir*_*dda 21

提取更多细节 - (这里%an指作者)

用这个 :-

git log --author="username" --pretty=format:"%h - %an, %ar : %s"
Run Code Online (Sandbox Code Playgroud)

  • 如果您希望他们的电子邮件地址使用格式“%ae”而不是“%an”(它给出了名称)。 (4认同)

Joh*_*lip 17

cat | git log --author="authorName" > author_commits_details.txt
Run Code Online (Sandbox Code Playgroud)

这将以文本格式提交您的提交.

  • `cat |`的目的是什么? (19认同)
  • @KeithThompson 去追老鼠。 (6认同)

Luc*_*lli 13

如果您想过滤自己的提交:

git log --author="<$(git config user.email)>"
Run Code Online (Sandbox Code Playgroud)


thr*_*ree 12

您甚至可以通过简单地使用部分用户名来缩写它:

git log --author=mr  #if you're looking for mrfoobar's commits
Run Code Online (Sandbox Code Playgroud)


Ins*_*Bot 8

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

用法

```bash
$ git standup [-a <author name>] 
              [-w <weekstart-weekend>] 
              [-m <max-dir-depth>]
              [-f]
              [-L]
              [-d <days-ago>]
              [-D <date-format>] 
              [-g] 
              [-h]
```
Run Code Online (Sandbox Code Playgroud)

以下是每个标志的描述

- `-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
Run Code Online (Sandbox Code Playgroud)


sja*_*jas 6

由于另一个问题(可能是错误地错了?)被锁定,因此我将其放在这里:

向作者显示提交计数:

git shortlog -nse
Run Code Online (Sandbox Code Playgroud)

查找特定USERNAME的所有提交:

git log --author=USERNAME --oneline | awk '{print $1}' | xargs git show
Run Code Online (Sandbox Code Playgroud)


Fra*_*rte 5

通过在.bashrc文件中添加此小片段,以彩色显示x用户的n个日志。

gitlog() {
    if [ "$1" ] && [ "$2" ]; then
       git log --pretty=format:"%h%x09 %C(cyan)%an%x09 %Creset%ad%x09 %Cgreen%s" --date-order -n "$1" --author="$2"
    elif [ "$1" ]; then
       git log --pretty=format:"%h%x09 %C(cyan)%an%x09 %Creset%ad%x09 %Cgreen%s" --date-order -n "$1"
    else
        git log --pretty=format:"%h%x09 %C(cyan)%an%x09 %Creset%ad%x09 %Cgreen%s" --date-order
    fi
}

alias l=gitlog
Run Code Online (Sandbox Code Playgroud)

要显示Frank的最后10次提交:

l 10 frank

要显示任何人的最后20次提交:

l 20