使用gitlog时,如何按用户进行筛选,以便只看到该用户的提交?
当前回答
这对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/
其他回答
在github上还有一个秘密方法。。。
您可以在提交视图中通过附加param?author=github_handle。例如,链接https://github.com/dynjs/dynjs/commits/master?author=jingweno显示了Dynjs项目的提交列表
试试这个工具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
如果您使用IntelliJ,您可以转到
View -> Tool Windows -> Git
选择“日志”并单击“用户:全部”
然后键入作者的姓名,它将显示该作者的每一次提交
通过在.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弗兰克
要显示任何人的最后20次提交:
l 20
这对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/
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别