使用 git log
时,如何按用户过滤,以便只看到来自该用户的提交?
github
上看到相同的内容?
这适用于 git log
和 gitk - 查看历史记录的两种最常用的方式。
您无需使用全名:
git log --author="Jon"
将匹配“Jonathan Smith”所做的提交
git log --author=Jon
和
git log --author=Smith
也可以。如果您不需要任何空格,引号是可选的。
如果您打算搜索所有分支,而不仅仅是在您的存储库中搜索当前提交的祖先,请添加 --all
。
您还可以轻松匹配多个作者,因为正则表达式是此过滤器的基础机制。所以要列出乔纳森或亚当的提交,你可以这样做:
git log --author="\(Adam\)\|\(Jon\)"
为了排除特定作者或一组作者使用正则表达式(如 in this question 所述)的提交,您可以将 negative lookahead 与 --perl-regexp
开关结合使用:
git log --author='^(?!Adam|Jon).*$' --perl-regexp
或者,您可以使用 bash
和管道排除 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/
git log --author="that user"
在github上也有一个秘密的方式...
您可以通过附加参数 ?author=github_handle
在提交视图中按作者过滤提交。例如,链接 https://github.com/dynjs/dynjs/commits/master?author=jingweno 显示了对 Dynjs 项目的提交列表
git help log
为您提供 git log 的联机帮助页。按 / 搜索“作者”,然后键入“作者”,然后按 Enter。键入“n”几次以进入相关部分,其中显示:
git log --author="username"
正如已经建议的那样。
请注意,这将为您提供提交的作者,但在 Git 中,作者可以是与提交者不同的人(例如在 Linux 内核中,如果您以普通用户身份提交补丁,则它可能由另一个管理用户提交.) 有关详细信息,请参阅 Difference between author and committer in Git?)
大多数情况下,用户指的是提交者和作者。
提取更多细节 - (这里 %an
指作者)
用这个 :-
git log --author="username" --pretty=format:"%h - %an, %ar : %s"
%ae
而不是 %an
(它给出了名称。)
--author
实际上是按作者姓名而不是提交者姓名进行搜索。我会将 "username"
更改为作者
如果要过滤自己的提交:
git log --author="<$(git config user.email)>"
由于另一个问题(可能是错误的?)被锁定,我将把它放在这里:
向作者展示他们的提交计数:
git shortlog -nse
查找特定 USERNAME 的所有提交:
git log --author=USERNAME --oneline --color=never | awk '{print $1}' | xargs git show
xargs git show
部分的任何输出,也许像我一样,您需要将 --color=never
添加到 git log
部分(我忘记了我的配置中的颜色设置有时会弄乱其他东西) .
cat | git log --author="authorName" > author_commits_details.txt
这会以文本格式提供您的提交。
cat |
的用途是什么?
试试这个工具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 log --author=mr #if you're looking for mrfoobar's commits
通过在 .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
要显示 Frank 的最后 10 次提交:
l 10 frank
要显示任何人的最后 20 次提交:
l 20
如果使用 GitHub:
去分店
点击提交
它将以以下格式显示列表
branch_x: < comment>
author_name committed 2 days ago
查看单个作者的提交;单击 author_name ,您可以在该分支上看到该作者的所有提交
虽然,有很多有用的答案。然而,只是为了添加另一种方式。你也可以使用
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
在这里,<Author Name>
在当前分支下总共完成了 5 次提交。然而,您也可以使用 --all
在 git 存储库中强制搜索 (所有分支)。
一个问题: git 在内部尝试将输入 <author name>
与 git 数据库中作者的姓名和电子邮件相匹配。它区分大小写。
您可以使用 = 或“空格”。例如以下两个命令返回相同
git log --author="Developer1"
git log --author "Developer1"
我的情况:我正在使用源代码树,我按照以下步骤操作:
按 CRL+3 更改下拉作者 键入名称“Vinod Kumar”
https://i.stack.imgur.com/TB2s3.png
一种可能的替代方法是使用名为 mergestat 的工具,该工具允许您针对存储库中的提交历史运行 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"
全面披露:我是该项目的维护者:)
如果您使用 IntelliJ,您可以访问
View -> Tool Windows -> Git
选择“日志”并单击“用户:全部”
https://i.stack.imgur.com/Xwaa5.png
https://i.stack.imgur.com/u14vF.png
然后输入作者的名字,它会显示这个作者的每一个提交
不定期副业成功案例分享
gitk
忽略其他作者的父提交? (它们以白色圆圈显示。)相比之下,git log --graph
不显示父提交;它只显示给定作者的提交。我希望在gitk
中看到相同的输出。 (已检查首选项和编辑视图 - 找不到任何有用的东西。)