Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

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

使用git log ,如何按用户筛选,以便仅看到该用户的提交?

  ask by markdorison translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This works for both git log and gitk - the 2 most common ways of viewing history.

(这适用于git loggitk查看历史记录的两种最常见方式。)

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

and

(和)

git log --author=Smith

would also work.

(也可以。)

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

(如果不需要空格,则引号是可选的。)

Add --all if you intend to search all branches and not just the current commit's ancestors in your repo.

(如果要搜索所有分支,而不是仅搜索--all当前提交的祖先,请添加--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 lookahead in combination with the --perl-regexp switch:

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

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

Alternatively, you can exclude commits authored by Adam by using bash and 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 %an with %cn .

(如果要排除Adam提交(但不一定是作者)的提交,请将%an替换%an %cn 。)

More details about this are in my blog post here: http://dymitruk.com/blog/2012/07/18/filtering-by-author-name/

(有关此操作的更多详细信息,请参见我的博客文章: http : //dymitruk.com/blog/2012/07/18/filtering-by-author-name/)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...