如何查看一个用户提交的 git 日志? [英] How can I view a git log of just one user's commits?

查看:41
本文介绍了如何查看一个用户提交的 git 日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 git log 时,如何按用户进行过滤,以便只看到来自该用户的提交?

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

推荐答案

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

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

git log --author=Smith

也可以.如果您不需要任何空格,引号是可选的.

would also work. The quotes are optional if you don't need any spaces.

添加 --all 如果您打算搜索所有分支,而不仅仅是您的存储库中当前提交的祖先.

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)"

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

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

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

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

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

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/

这篇关于如何查看一个用户提交的 git 日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆